I\'m encountering a bug in the Java compiler where the order of files submitted for compilation can cause code not to compile. I\'ve drilled down the code to isolate the sma
Here's how I would do it:
ActionSpec
interface to another Maven project. We usually have interfaces and common domain classes in their own project, e.g. foo-service-specs
.foo-service-impl
.foo-service-specs
project as a dependency in foo-service-impl
.By doing this, you can make sure that the compilation order is working, and it should also work for continuous integration.
It's the bug reported in http://bugs.sun.com/view_bug.do?bug_id=6724345
The workaround suggested should work if you are still using Java 6 compiler. The bug is fixed in Java 7.
I played around, and found that adding simple cast:
public static void main(String[] args) {
((ActionSpec)Actions.SKIP).run("hello");
}
solves this problem. Passing this enum as method parameter as interface would also do the trick
Try multiple executions of the compiler plugin. Using default-compile
as the first execution ID adds the new config to Maven's default compiler execution. Use the <includes/>
config elements in the default execution to compile the enums first. For the second execution you'd use a combination of <includes>
and <excludes>
, where <includes>
would be all of your code and excludes would be the enums already compiled.
I think this will work for your example program but I did not test it. I have tested something similar before with Maven 3 and it worked fine.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<goals><goal>compile</goal></goals>
<configuration>
<includes>
<include>**/Actions.*</include>
</includes>
</configuration>
</execution>
<execution>
<id>second</id>
<goals><goal>compile</goal></goals>
<configuration>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/Actions.*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
We had the same problem. Multiple executions of the maven compiler
plugin worked for us...