I am trying to use maven-processor-plugin for generating JPA metamodel java files and I set up my pom.xml as belows.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
Actually, I want to generate metamodel files (Entity_.java) to the same packages of their corresponding entities (Entity.java). Hence, I set up outputDirectory in the plugin as
<outputDirectory>${basedir}/src/main/java</outputDirectory>
The first time of running is ok, but from later times when performing the metamodel java files re-generation, the plugin always turns out an error about file duplication.
My Question is
- Is there any way to config the plugin so that it could overwrite the existing files during re-generation?
In fact, to work around
- I must delete all generated files before any re-generation.
- I could point the outputDirectory to a different folder in /target, this location will be clean everytime Maven run, but this
leads to manually copy generated metamodel files to source folder
for update after re-generation.
Both of these are very inconvenient and I hope you guys could show me a proper solution.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…