如何使scala-maven-plugin看到由maven-compiler-plugin编译的类?

时间:2016-07-21 05:13:04

标签: java scala maven

由于Scalac(https://issues.scala-lang.org/browse/SI-9853)中的错误,我无法使用scala-maven-plugin构建我的Java源代码。

分割构建以便 maven-compiler-plugin 编译Java,而 scala-maven-plugin 编译Scala很容易,而源代码驻留在< strong> src / main / java 和 src / main / scala 。 现在我遇到了Scala类无法看到Java类的问题。 在进行mvn clean编译时,我发现没有找到&#39;对于Scala类所需的所有Java类。检查&#39;目标/班级&#39;表明Java类在那里。

我尝试将Scala-build移动到不同的阶段,但结果保持不变。

如何让Scala-build看到目标/类中已有的类?

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

1 个答案:

答案 0 :(得分:1)

最简单的解决方法是将其拆分为两个子模块。这样您就可以将Java类作为依赖项引用。之后生成Uber jar或阴影jar,内联两个模块。