我想从 pom.xml 依赖项生成一个类路径文件。我需要它,所以在测试期间我有所有依赖项的类路径(稍后打包成一个包)
maven-dependency-plugin
不适合我有两个原因:
- 它生成存储库中文件的路径,因此要使用它们首先需要运行的其他模块
install
他们的阶段(我想要有像/some/root/othermodule/target/classes
)
- 它不包括工件自己的路径(
target/classes
),这意味着我需要稍后在代码中添加它,这很尴尬
所以我正在寻找另一个插件(或者如何正确运行maven-dependency-plugin
)
我最终使用了 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))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)