在解决Maven-repository的依赖关系时,Gradle必须下载相应的pom文件。我想从Gradle脚本中访问此文件并将其保存在某处。我怎么能这样做?
答案 0 :(得分:2)
看看Artifact Query API。以下是示例代码(Groovy):
def componentIds = configuration.compile.resolutionResult.allDependencies.collect { it.selected.id }
def result = project.dependencies.createArtifactResolutionQuery()
.forComponents(componentIds)
.withArtifacts(MavenModule, MavenPomArtifact)
.execute()
for (component in result.resolvedComponents) {
component.getArtifacts(MavenPomArtifact).each { println "POM file for ${component.id}: ${it.file}" }
}
我在my plugin in Kotlin中使用相同的API。
答案 1 :(得分:1)
您可以简单地声明对POM本身的依赖。
configurations {
pom
}
dependencies {
pom 'org.foo:some-lib:1.0.0@pom'
}
task copyPom(type: Copy) {
into "${buildDir}/poms"
from configurations.pom
}