Search code examples
scalamavenmaven-2maven-3maven-assembly-plugin

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.


Solution

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