Java- Scala cross-compilation error - cannot find symbol

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

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

Cause

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.

 

Resolution

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 .

 

 

Last modified on Jul 16, 2015

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.