Reputation: 23
I am trying to do two things here :
1. Copy the dependencies to two different folders :
a. package1 - contains my other project dependencies
b. package2 - contains third party jar dependencies
2. Write all the jars in both package1 and package2 to another file 'dependencyJars.txt'
The dependencyJars.txt must contain all the jars in package1 and package2 as well.
I am unable to achieve that.
The second build-classpath overwrites the dependencies written by first build-classpath.
So at the end, only package2 dependencies are available in dependencyJars.txt.
Is there any way to achieve the above thing, i.e, the first execution writes its dependencies to dependencyJars.txt, and then the second execution appends its
dependencies in the file dependencyJars.txt?
My POM content is as follows :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>build-package1-dependencies</id>
<phase>package</phase>
<goals>
<goal>build-classpath</goal>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<appendOutput>true</appendOutput>
<prefix>package1/</prefix>
<outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
<excludeGroupIds>com.test.package2</excludeGroupIds>
<outputDirectory>${project.build.directory}/package1-jars/</outputDirectory>
<outputFile>D:/new2/dependencyJars.txt</outputFile>
<overWriteIfNewer>true</overWriteIfNewer>
<regenerateFile>false</regenerateFile>
</configuration>
</execution>
<execution>
<id>build-package2-dependencies</id>
<phase>package</phase>
<goals>
<goal>build-classpath</goal>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<appendOutput>true</appendOutput>
<prefix>package2/</prefix>
<outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
<excludeGroupIds>com.test.package1</includeGroupIds>
<outputDirectory>${project.build.directory}/package2-jars/</outputDirectory>
<outputFile>D:/new2/dependencyJars.txt</outputFile>
<overWriteIfNewer>true</overWriteIfNewer>
<regenerateFile>false</regenerateFile>
</configuration>
</execution>
</executions>
Upvotes: 2
Views: 1836
Reputation: 12943
Is there any way to achieve the above thing, i.e, the first execution writes its dependencies to dependencyJars.txt, and then the second execution appends its dependencies in the file dependencyJars.txt?
That doesn't seem to be possible, no configuration is documented to prevent the file to be overriden. This behavior seems acceptable, otherwise when running the same build twice you'll have a duplication of the same classpath entries in the same file.
However you can configure each execution to write to a different file and then concat both files, for example using the Maven AntRun Plugin:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>concat-build-classpath</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<concat destfile="D:/new2/dependencyJars.txt" >
<fileset file="D:/new2/dependencyJars1.txt" />
<fileset file="D:/new2/dependencyJars2.txt" />
</concat>
</target>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 1