I have a section in my pom.xml that generates OpenJPA's metamodel like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>generate-entity-metamodel</id>
<phase>generate-sources</phase>
<goals>
<goal>
compile
</goal>
</goals>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<proc>only</proc>
<compilerArgument>-Aopenjpa.metamodel=true</compilerArgument>
<generatedSourcesDirectory>${project.build.directory}/generated-sources/openjpa-metamodel</generatedSourcesDirectory>
</configuration>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
The "problem" I have is that this "default" execution of maven-compiler-plugin is called only when there is a change in source code - which is expected, but "generate-entity-metamodel" is called always which leads to failure in build since those generate classes already exist from a previous build. I have always to do mvn clean compile
in order for my build to succeed.
How can I fix this and have "generate-entity-metamodel" called only when there were changes in source files?
Here's the output when I do
mvn test
[INFO] --- build-helper-maven-plugin:1.8:add-source (default) @ icmynet-core ---
[INFO] Source directory: E:\Projekti\release-repo\icmynet\trunk\icmynet-core\target\generated-sources\openjpa-metamodel added.
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (generate-entity-metamodel) @ icmynet-core ---
[INFO] Changes detected - recompiling the module!
Hm... why are there "changes detected"?