由于 Scalac 中的错误 ( https://issues.scala-lang.org/browse/SI-9853 ),我无法使用 scala-maven-plugin 构建我的 Java 源代码。
拆分构建,以便 Java 由 maven-compiler-plugin 编译,Scala 由 scala-maven-plugin 编译,这很容易,源代码位于 < src/main/java 和 src/main/scala 。 现在我遇到了 Scala 类看不到 Java 类的问题。 在进行 mvn clean 编译时,我“找不到”Scala 类所需的所有 Java 类。检查“目标/类”显示 Java 类存在。
我尝试将 Scala 构建移至不同的阶段,但结果保持不变。
如何让 Scala 构建看到目标/类中已经可用的类?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.codepitbull.maven</groupId>
<artifactId>maven-scalac-bug</artifactId>
<version>3.4.0-SNAPSHOT</version>
<name>Scalac + Javac</name>
<properties>
<scala.version>2.11.8</scala.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<scope>provided</scope>
<version>${scala.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<sendJavaToScalac>false</sendJavaToScalac>
<args>
<arg>-target:jvm-1.8</arg>
<arg>-feature</arg>
<arg>-deprecation</arg>
<arg>-explaintypes</arg>
<arg>-unchecked</arg>
<arg>-Xlint</arg>
</args>
</configuration>
<executions>
<execution>
<id>java-compile-first</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
最佳答案
最简单的解决方法是将其分成两个子模块。这样您就可以将 Java 类作为依赖项进行引用。之后生成一个 Uber jar 或内联两个模块的阴影 jar。
关于java - 如何使 scala-maven-plugin 查看由 maven-compiler-plugin 编译的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38495349/