Creating a classpath file with Maven

I would like to generate a classpath file from pom.xml dependencies. I need this, so during the tests I have a path to the classes of all dependencies (which are later packaged in a package)

maven-dependency-plugin not suitable for me for two reasons:

  • it creates paths to files in the repository, so to use other modules they first need to run a phase installfor them (I would like to have paths like /some/root/othermodule/target/classes)
  • it does not contain its own artifact path ( target/classes), which means that I need to add it later in the code, which is inconvenient

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

+3
source share
1 answer

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>

, , /, . , :

file.write(project.runtimeClasspathElements.join(File.pathSeparator))
+2

Source: https://habr.com/ru/post/1769961/


All Articles