我的pom.xml中有一个部分生成OpenJPA的元模型,如下所示:
<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>
我遇到的“问题”是只有在源代码发生变化时才会调用maven-compiler-plugin的“默认”执行 - 这是预期的,但总是会调用“generate-entity-metamodel”导致构建失败,因为那些生成类已经存在于以前的构建中。为了让我的构建成功,我总是来mvn clean compile
。
如何修复此问题并仅在源文件发生更改时调用“generate-entity-metamodel”?
<小时/> 这是我
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!
嗯......为什么会发现“检测到变化”?