使用不同的 Scala 版本生成两个相同 Maven 项目的 jar
Generate two jars of same Maven project using different Scala version
我有一个带有 Scala 代码的 Maven 项目,我想根据不同的 Scala 版本(2.10.6 和 2.11.8)生成两个 jar。
如果有人请建议解决方案,我如何在单个 maven 安装执行中实现这一点,或者是否有任何其他方法在 Maven 中使用一些 Maven 插件实现这一点。
创建针对不同版本的 Scala 覆盖依赖项的配置文件。您需要在两个配置文件上 运行 mvn install
。有关详细信息,请参阅:different-dependencies-for-different-build-profiles-in-maven
您还需要更改配置文件中的工件名称/版本以区分这两者。
我可以使用多次执行来解决这个问题。
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-version-2.10</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.10.6</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.10</outputDir>
</configuration>
</execution>
<execution>
<id>scala-version-2.11</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.11</outputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>scala-2.10</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.10</classifier>
<excludes>
<exclude>scala-2.11/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>scala-2.11</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.11</classifier>
<excludes>
<exclude>scala-2.10/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
我有一个带有 Scala 代码的 Maven 项目,我想根据不同的 Scala 版本(2.10.6 和 2.11.8)生成两个 jar。 如果有人请建议解决方案,我如何在单个 maven 安装执行中实现这一点,或者是否有任何其他方法在 Maven 中使用一些 Maven 插件实现这一点。
创建针对不同版本的 Scala 覆盖依赖项的配置文件。您需要在两个配置文件上 运行 mvn install
。有关详细信息,请参阅:different-dependencies-for-different-build-profiles-in-maven
您还需要更改配置文件中的工件名称/版本以区分这两者。
我可以使用多次执行来解决这个问题。
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-version-2.10</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.10.6</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.10</outputDir>
</configuration>
</execution>
<execution>
<id>scala-version-2.11</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<scalaVersion>2.11.8</scalaVersion>
<outputDir>${project.build.outputDirectory}/scala-2.11</outputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>scala-2.10</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.10</classifier>
<excludes>
<exclude>scala-2.11/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>scala-2.11</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>scala-2.11</classifier>
<excludes>
<exclude>scala-2.10/**</exclude>
<exclude>sparkScala/**</exclude>
<exclude>sparksql/**</exclude>
<exclude>*.timestamp</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>