How to stop Apache maven <outputDirectory> to overwrite folder

I have the following directory hierarchy:

generated | | -->java 

The Java directory has the following package: com.model

which contains java models that I copy / paste somewhere before compiling the application.

The problem is that I use the protocol buffer, and I tell maven to output the generated files to the same previous directory, but on the new package:

Result: the protocol buffer generates a new packet and deletes the old packet.
I do not know why this happens, although the package names are different?

Here is this part of pom that I use to generate java from the protocol buffer:

  <plugin> <groupId>com.google.protobuf.tools</groupId> <artifactId>maven-protoc-plugin</artifactId> <configuration> <protocExecutable>C:\protoc.exe</protocExecutable> <protoSourceRoot>./src/proto</protoSourceRoot> <outputDirectory>./src/generated/java</outputDirectory> </configuration> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> 
+4
source share
2 answers

if you look at the code for the plugin, you will see that the code was hard-coded to clean the directory:

https://github.com/dtrott/maven-protoc-plugin/blob/master/src/main/java/com/google/protobuf/maven/AbstractProtocMojo.java#L154

 // Quick fix to fix issues with two mvn installs in a row (ie no clean) cleanDirectory(outputDirectory); 

There are two ways to solve this: either set the output directory to the temp directory, and then use the maven copy plugin or the maven build plugin to copy files to the directory of your choice or change the maven plugin to delete this line (or better yet configure it).

Tommy

+3
source

I solved my problem as follows:

 <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>generate-resources</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <delete dir="./destination"/> <copy todir="./destination"> <fileset dir="./source"/> </copy> <delete dir="./source"/> </tasks> </configuration> </execution> </executions> </plugin> 

However, I get this error "An Ant BuildException: only one of the files and todir can be installed"

+1
source

All Articles