Reputation: 29123
I'd like to generate a classpath file from pom.xml dependencies. I need it so during tests I have the classpath of all dependencies (that are later packaged into a bundle)
maven-dependency-plugin
does not suit me for two reasons:
install
phase for them (I'd like to have paths like /some/root/othermodule/target/classes
)target/classes
), which means I need to add it later in code, which is awkwardSo I'm looking for another plugin (or how to properly run maven-dependency-plugin
)
Upvotes: 5
Views: 2996
Reputation: 29123
I ended up using GMaven:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def all = project.runtimeArtifacts.collect{
def aid = "${it.groupId}:${it.artifactId}:${it.version}"
def p = project.projectReferences[aid]
p?.build?.outputDirectory ?: it.file.path
} + project.build.outputDirectory
def file = new File(project.build.directory, ".classpath")
file.write(all.join(File.pathSeparator))
</source>
</configuration>
</execution>
</executions>
</plugin>
The code is a bit complex since I wanted paths to target/classes when possible. If this is not required, one can do :
file.write(project.runtimeClasspathElements.join(File.pathSeparator))
Upvotes: 2