简体   繁体   中英

Generate two jars of same Maven project using different Scala version

I am having a Maven project with Scala code and i want to generate the two jars based on the different Scala versions (2.10.6 and 2.11.8). If someone please suggest the solution how i can achieve this in single maven install execution or if there is any other way of achieving this in Maven using some Maven plug in.

Create profiles that have dependency overridden for different versions of Scala. You will need to run mvn install on both profiles. For more information see: different-dependencies-for-different-build-profiles-in-maven

Also you need to alter artifact name / version in profiles to make distinction between those two.

I am able to solve this problem using multiple executions.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM