Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between maven-compiler-plugin and scala-maven-plugin?

Tags:

I am currently dealing with a project mixing both Java and Scala (Spark). And as if this was not enough, some of my dependencies import another versions of Spark and Scala (not retro-compatible)...

To sum up, here is what my dependency tree might look like:

myProjectA
\_ myLibB
| \_ spark 1.5.2 (excluded in my pom.xml)
|  \_ scala 2.10.4 (excluded in my pom.xml)
\_ spark 2.2.0 (with Scala 2.11)
|  \_ scala 2.11.7
\_ scala 2.11.11
\_ java 8

After one small modification on a map inside my project the compilation doesn't work anymore... FYI, the modification consisted in adding an element in a hard-coded map.

Hence, I am looking for a solution to compile my project. I am currently using this build configuration:

  <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.1.3</version>
    <executions>
      <execution>
        <goals>
          <goal>compile</goal>
          <goal>testCompile</goal>
        </goals>
        <configuration>
          <args>
            <arg>-dependencyfile</arg>
            <arg>${project.build.directory}/.scala_dependencies</arg>
          </args>
        </configuration>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4.1</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

I realized that this other configuration seems to work just fine even after the change that made the previous configuration bug (I replaced the scala-maven-plugin with the maven-compiler-plugin):

  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4.1</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>

Two questions:
- what is the difference between maven-compiler-plugin and scala-maven-plugin?
- can maven-compiler-plugin compile efficiently Scala code/mixed Java-Scala code?

like image 238
belka Avatar asked Dec 19 '17 15:12

belka


1 Answers

what is the difference between maven-compiler-plugin and scala-maven-plugin?

Maven compiler plugin is primarily to compile java sources. Scala plugin can compile both Java and Scala sources. Maven compiler plugin will always be the first plugin to be invoked during compile phase. As it can't compile scala sources The solutions are either to use some pre-compile phase to run scala and java compatible compiler plugin. In fact you don't need maven compiler plugin if you use scala plugin.

can maven-compiler-plugin compile efficiently Scala code/mixed Java-Scala code?

No

Please go thru this link

like image 160
nkasturi Avatar answered Sep 22 '22 12:09

nkasturi