混合Scala / Java无法编译,错误:无法访问

时间:2014-10-03 10:12:44

标签: java scala maven

我遇到了混合scala / java项目的问题并且需要编译所有内容。我在许多网站上建议使用scala-maven-plugin和maven-compiler-plugin,如(http://davidb.github.io/scala-maven-plugin/example_java.html)。

生成的错误消息是(SResize是一个scala类)

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project tipl-spark: Compilation failure
[ERROR] error: cannot access SResize$sstats$4$
[ERROR] -> [Help 1]
[ERROR] 

在构建部分

用于scala-maven-plugin

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.2.0</version>
            <executions>

                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
           <execution>
               <id>attach-scaladocs</id>
               <phase>verify</phase>
               <goals>
                   <goal>doc-jar</goal>
               </goals>
           </execution>
       </executions>
            <configuration>
                <scalaVersion>${scala.version}</scalaVersion>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <encoding>UTF-8</encoding>
                <args>
                    <arg>-unchecked</arg>
                    <arg>-deprecation</arg>
                    <arg>-feature</arg>
                    <arg>-language:postfixOps</arg>
                </args>
                <jvmArgs>
                    <jvmArg>${java.memory.min}</jvmArg>
                    <jvmArg>${java.memory.max}</jvmArg>
                    <jvmArg>-XX:PermSize=${PermGen}</jvmArg>
                    <jvmArg>-XX:MaxPermSize=${MaxPermGen}</jvmArg>
                </jvmArgs>

            </configuration>
        </plugin>

用于maven编译器

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

1 个答案:

答案 0 :(得分:0)

它最终成为一个非常奇怪的错误,一开始就丢失了scala库依赖,这导致了maven编译器的问题(我猜?)

   <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>${scala.version}</version>
    </dependency>

最终的scala-maven-plugin是

      <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.2.0</version>
            <executions>

                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
           <execution>
               <id>attach-scaladocs</id>
               <phase>verify</phase>
               <goals>
                   <goal>doc-jar</goal>
               </goals>
           </execution>
       </executions>
            <configuration>
                <scalaVersion>${scala.compile.version}</scalaVersion>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <encoding>UTF-8</encoding>
                <args>
                    <arg>-unchecked</arg>
                    <arg>-deprecation</arg>
                    <arg>-feature</arg>
                    <arg>-language:postfixOps</arg>
                </args>
                <jvmArgs>
                    <jvmArg>${java.memory.min}</jvmArg>
                    <jvmArg>${java.memory.max}</jvmArg>
                    <jvmArg>-XX:PermSize=${PermGen}</jvmArg>
                    <jvmArg>-XX:MaxPermSize=${MaxPermGen}</jvmArg>
                </jvmArgs>
                 <javacArgs>
                    <javacArg>-source</javacArg>
                    <javacArg>${java.version}</javacArg>
                    <javacArg>-target</javacArg>
                    <javacArg>${java.version}</javacArg>
                </javacArgs>

            </configuration>
        </plugin>

使用以下maven-compiler-plugin(之后)

        <!-- use the the maven compiler plugin settings from http://davidb.github.io/scala-maven-plugin/example_java.html -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

现在一切都完美编译

相关问题