使用 Maven 生成类路径文件

Itt*_*ayD 5 plugins dependencies maven-2

我想从 pom.xml 依赖项生成一个类路径文件。我需要它,所以在测试期间我有所有依赖项的类路径(稍后打包成一个包)

maven-dependency-plugin不适合我有两个原因:

  • 它生成存储库中文件的路径,因此要使用其他模块,它们首先需要install为它们运行阶段(我希望有类似的路径/some/root/othermodule/target/classes
  • 它不包含工件自己的路径(target/classes),这意味着我需要稍后在代码中添加它,这很尴尬

所以我正在寻找另一个插件(或如何正确运行maven-dependency-plugin

Itt*_*ayD 2

我最终使用了 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>
Run Code Online (Sandbox Code Playgroud)

该代码有点复杂,因为我希望尽可能获得目标/类的路径。如果不需要这样做,可以这样做:

file.write(project.runtimeClasspathElements.join(File.pathSeparator))
Run Code Online (Sandbox Code Playgroud)