maven-compiler-plugin和scala-maven-plugin有什么区别?

时间:2017-12-19 15:35:01

标签: java scala maven apache-spark

我目前正在处理混合Java和Scala(Spark)的项目。并且好像这还不够,我的一些依赖项会导入另一个版本的Spark和Scala(不兼容复古)......

总而言之,这是我的依赖树的样子:

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

在我的项目内的地图上进行一次小修改之后,编译不再起作用了......仅供参考,修改包括在硬编码地图中添加元素。

因此,我正在寻找一个编译我的项目的解决方案。我目前正在使用此构建配置:

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

我意识到这个其他配置似乎工作得很好,即使在之前的配置错误发生变化之后(我将scala-maven-plugin替换为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>

两个问题:
    - maven-compiler-pluginscala-maven-plugin之间的区别是什么?     - 可以maven-compiler-plugin有效地编译Scala代码/混合Java-Scala代码吗?

1 个答案:

答案 0 :(得分:2)

maven-compiler-plugin和scala-maven-plugin有什么区别?

Maven编译器插件主要用于编译java源代码。 Scala插件可以编译Java和Scala源代码。 Maven编译器插件将始终是在编译阶段调用的第一个插件。因为它无法编译scala源解决方案要么使用一些预编译阶段来运行scala和java兼容的编译器插件。事实上,如果你使用scala插件,你就不需要maven编译器插件。

maven-compiler-plugin能否有效地编译Scala代码/混合Java-Scala代码?

没有

请通过此link

相关问题