【问题标题】:Generate two jars of same Maven project using different Scala version使用不同的 Scala 版本生成两个相同的 Maven 项目
【发布时间】:2023-03-31 19:12:01
【问题描述】:

我有一个带有 Scala 代码的 Maven 项目,我想根据不同的 Scala 版本(2.10.6 和 2.11.8)生成两个 jar。 如果有人请提出解决方案,我如何在单个 Maven 安装执行中实现这一点,或者如果有任何其他方法可以使用一些 Maven 插件在 Maven 中实现这一点。

【问题讨论】:

    标签: scala maven maven-2 maven-3 maven-assembly-plugin


    【解决方案1】:

    我可以通过多次执行来解决这个问题。

    <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>
    

    【讨论】:

      【解决方案2】:

      创建为不同版本的 Scala 覆盖了依赖项的配置文件。您需要在两个配置文件上运行 mvn install。更多信息请见:different-dependencies-for-different-build-profiles-in-maven

      您还需要更改配置文件中的工件名称/版本以区分这两者。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多