2

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.

Ankur Jain
  • 43
  • 1
  • 9

2 Answers2

2

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>

Ankur Jain
  • 43
  • 1
  • 9
1

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.

pirho
  • 11,565
  • 12
  • 43
  • 70