使用Maven对Scala独立应用程序进行编译打包

编译插件 - java
<!-- the Maven compiler plugin will compile Java source files -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.5.1</version>

</plugin>

编译插件 - scala
<!-- the Maven Scala plugin will compile Scala source files -->

<plugin>

<groupId>net.alchim31.maven</groupId>

<artifactId>scala-maven-plugin</artifactId>

<version>3.2.2</version>

<executions>

<execution>

<goals>

<goal>compile</goal>

<goal>testCompile</goal>

</goals>

</execution>

</executions>

</plugin>

打jar包插件
<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-jar-plugin</artifactId>

<version>3.0.2</version>

</plugin>

打包插件 - assembly配置
<!-- 打包 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-assembly-plugin</artifactId>

<version>2.6</version>

<configuration>

<descriptors>

<descriptor>package.xml</descriptor>

</descriptors>

</configuration>

<executions>

<execution>

<id>make-assembly</id>

<phase>package</phase>

<goals>

<goal>single</goal>

</goals>

</execution>

</executions>

</plugin>

配置 - package.xml
<assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">

<id>jar</id>

<formats>

<format>zip</format>

</formats>

<dependencySets>

<dependencySet>

<includes>

<include>com.google.guava</include>

<include>com.google.code.gson</include>

<include>org.msgpack:*</include>

</includes>

<!--<excludes>-->

<!--<exclude>com.google.guava</exclude>-->

<!--</excludes>-->

<useProjectArtifact>false</useProjectArtifact>

<outputDirectory>/libs</outputDirectory>

</dependencySet>

</dependencySets>

<fileSets>

<fileSet>

<directory>target</directory>

<includes>

<include>*.jar</include>

</includes>

<outputDirectory>/</outputDirectory>

</fileSet>

<fileSet>

<directory>src/main/resources</directory>

<includes>

<include>*</include>

<include>*/*.sh</include>

<include>*/*/*.sh</include>

<include>*/*.conf</include>

</includes>

<outputDirectory>/</outputDirectory>

</fileSet>

</fileSets>

</assembly>

完整的配置 - pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

 

<!-- 版本管理 -->

<modelVersion>4.0.0</modelVersion>

<parent>

<groupId>com.talkingdata</groupId>

<artifactId>centralized-configuration</artifactId>

<version>0.0.1</version>

</parent>

 

<groupId>test</groupId>

<artifactId>maven-test</artifactId>

<version>1.0.30-SNAPSHOT</version>

 

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

<scala.version>2.11.8</scala.version>

<scala.binary.version>2.11</scala.binary.version>

<spark.version>2.3.0</spark.version>

<angel.version>1.1.0</angel.version>

</properties>

 

<dependencies>

<!-- bloomfilter -->

<dependency>

<groupId>com.google.guava</groupId>

<artifactId>guava</artifactId>

<version>19.0</version>

</dependency>

 

<!--MsgPack-->

<dependency>

<groupId>com.talkingdata.analytics</groupId>

<artifactId>msgpack</artifactId>

<version>0.0.121.analytics-collector</version>

</dependency>

<dependency>

<groupId>org.msgpack</groupId>

<artifactId>msgpack-scala_${scala.binary.version}</artifactId>

<version>0.6.11</version>

</dependency>

 

</dependencies>

 

<build>

<defaultGoal>install</defaultGoal>

<sourceDirectory>src/main/scala</sourceDirectory>

<testSourceDirectory>src/test/scala</testSourceDirectory>

<finalName>maven-test</finalName>

 

<plugins>

 

<!-- the Maven compiler plugin will compile Java source files -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.5.1</version>

</plugin>

 

<!-- the Maven Scala plugin will compile Scala source files -->

<plugin>

<groupId>net.alchim31.maven</groupId>

<artifactId>scala-maven-plugin</artifactId>

<version>3.2.2</version>

<executions>

<execution>

<goals>

<goal>compile</goal>

<goal>testCompile</goal>

</goals>

</execution>

</executions>

</plugin>

 

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-jar-plugin</artifactId>

<version>3.0.2</version>

</plugin>

 

<!-- 打包 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-assembly-plugin</artifactId>

<version>2.6</version>

<configuration>

<descriptors>

<descriptor>package.xml</descriptor>

</descriptors>

</configuration>

<executions>

<execution>

<id>make-assembly</id>

<phase>package</phase>

<goals>

<goal>single</goal>

</goals>

</execution>

</executions>

</plugin>

 

</plugins>

</build>

 

</project>

posted @ 2023-10-27 17:49  Weebles  阅读(107)  评论(0编辑  收藏  举报