Java- Scala cross-compilation error - cannot find symbol

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

症状

Running Clover with mixed Java-Scala project having cross-dependencies between Java and Scala classes, results in compiler complaining about missing Scala classes:

[ERROR] /project/target/clover/src-instrumented/test/java/HelloJavaWorld.java:3: error: package test.scala does not exist
[ERROR] import test.scala.HelloScalaProvider;
[ERROR]                  ^
[ERROR] /project/target/clover/src-instrumented/test/java/HelloJavaWorld.java:8: error: cannot find symbol
[ERROR]         __CLR4_0_422ic5u5wnb.R.inc(3);final String provide = HelloScalaProvider.provide();
[ERROR]                                                              ^
[ERROR]   symbol:   variable HelloScalaProvider
[ERROR]   location: class HelloJavaWorld
[ERROR] 2 errors

原因

Typically, project structure looks like this:

project/
    src/
        main/
            java/
            scala/
        test/
            java/
            scala/

 

Normally, Scala plugin looks for *.scala files in compilation source roots directory (here in src/*/scala).  However, when Clover is enabled, it:

  • instruments *.java files from original source roots and writes them to the target/clover/src-(test-)instrumented folders
  • next it copies all other files from original source roots to target/clover/src-(test-)instrumented folders (to ensure that resource files won't be missing etc)
  • next it removes original source roots and sets target/clover/src-(test-)instrumented as new roots

Because of this, when Scala compiler runs, it can't find *.scala files.

 

ソリューション

Configure build-helper-maven-plugin to add Scala directories to compile source roots. Example: 

<build>
  <plugins>
	<plugin>
    	<groupId>org.codehaus.mojo</groupId>
	    <artifactId>build-helper-maven-plugin</artifactId>
	    <version>1.9.1</version>
	    <executions>
	        <execution>
	            <id>add-source</id>
	            <phase>validate</phase>
	            <goals>
	                <goal>add-source</goal>
	            </goals>
	            <configuration>
	                <sources>
    	                <source>src/main/scala</source>
        	        </sources>
	            </configuration>
    	    </execution>
	        <execution>
	            <id>add-test-source</id>
	            <phase>validate</phase>
	            <goals>
	                <goal>add-test-source</goal>
	            </goals>
	            <configuration>
	                <sources>
    	                <source>src/test/scala</source>
        	        </sources>
	            </configuration>
    	    </execution>
         </executions>
	</plugin>
  </plugins>
</build>

Since Scala is not supported, code coverage will be reported only for Java classes CLOV-932 - Getting issue details... STATUS .

 

 

最終更新日 2015 年 7 月 16 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.