Compilation error with Clover enabled - missing type, cannot find symbol

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

When Clover is enabled compilation fails with a missing type error, for example:

[javac] /workspace/com/samples/OtherClass.java:11: cannot find symbol
[javac] symbol  : variable BuildTime
[javac] location: class com.samples.OtherClass
[javac]         __CLR4_0_3b0b0i9zeh8ey.R.inc(397);System.out.println(BuildTime.BUILD_TIME);
[javac]                                                              ^
[javac] 1 error

 

Cause

Errors related with a missing symbol might occur when:

  • you have source code generation integrated with your build process and
  • sources are being generated after Clover's instrumentation

 

For example, if you have a Maven-based build and you use maven-antrun-plugin or maven-exec-plugin to generate source files:

 

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <target>
         <copy file="${project.build.sourceDirectory}/com/samples/BuildTime.java.gen."
               tofile="${project.build.sourceDirectory}/com/samples/BuildTime.java" overwrite="true"/>
        </target>
      </configuration>
    </execution>
  </executions>
</plugin>  

 

and you run standard Clover instrumentation, such as:

mvn clean clover:setup test clover:clover clover:aggregate

 

Clover's code instrumentation (clover:setup) will occur before code generation (as the 'generate-sources' phase will be triggered by the 'test' phase). Clover will also change source roots (e.g. from 'src/main/java' to 'target/clover/src-instrumented'). As a consequence, the BuildTime.java file will be written to an old source root ('src/main/java') and will not be compiled at all.

 

Resolution

Please verify if your build process contains any code/resource generation. If it does, make sure that

  • Clover is initialized and sources are instrumented after all files are have already been generated
  • or ensure that generated sources will be copied to folder(s) containing instrumented files.

 

You can either do it in a command line:

 

mvn clean generate-sources clover:setup test

 

or you can bind the 'clover:setup' to a build phase which happens after the 'generate-sources' one:

 

<plugin>
  <groupId>com.atlassian.maven.plugins</groupId>
  <artifactId>clover-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>process-sources</phase>
      <goals>
        <goal>setup</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Last modified on Dec 8, 2015

Was this helpful?

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