简体   繁体   English

我怎样才能使scala-maven-plugin看到由maven-compiler-plugin编译的类?

[英]How can I make scala-maven-plugin make see classes compiled by maven-compiler-plugin?

I can't use the scala-maven-plugin to build my Java-sources due to a bug in Scalac ( https://issues.scala-lang.org/browse/SI-9853 ). 由于Scalac( https://issues.scala-lang.org/browse/SI-9853 )中的错误,我无法使用scala-maven-plugin构建我的Java源代码。

Splitting the build so that Java is compiled by the maven-compiler-plugin and Scala by the scala-maven-plugin was easy enough with the sources residing in src/main/java and src/main/scala . 使用src / main / javasrc / main / scala中的源代码,可以很容易地拆分构建,以便由maven-compiler-plugin编译 Java和由scala-maven-plugin 编译 Scala。 Right now I am running into the problem that the Scala-classes can't see the Java-classes. 现在,我遇到了Scala类看不到Java类的问题。 When doing mvn clean compile I get 'not found' for all Java-classes required by the Scala-classes. 在执行mvn clean编译时,对于Scala类所需的所有Java类,我都“找不到”。 Checking 'target/classes' shows that the Java-classes are there. 检查“目标/类”表明那里有Java类。

I tried moving the Scala-build to different phases but the results remain the same. 我尝试将Scala构建移动到不同的阶段,但结果保持不变。

How can I make the Scala-build see the classes already available in target/classes? 如何使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>

The easiest workaround would be to split it into two submodules. 最简单的解决方法是将其分为两个子模块。 That way you're able to reference the Java classes as dependency. 这样,您就可以将Java类引用为依赖项。 After that generate an Uber jar or shaded jar with both modules inlined. 之后,生成内联两个模块的Uber jar或有阴影的jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM