views:

23

answers:

1

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:

  • it generates paths to files in the repository, so to use other modules they first need to run install phase for them (I'd like to have paths like /some/root/othermodule/target/classes)
  • it doesn't include the artifact's own path (target/classes), which means I need to add it later in code, which is awkward

So I'm looking for another plugin (or how to properly run maven-dependency-plugin)

A: 

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))
IttayD