2014-10-06 158 views
2

在解析Maven-repository中的依赖项时,Gradle必须下载相应的pom文件。我想从Gradle脚本中访问此文件并将其保存在某处。我怎样才能做到这一点?为Gradle中的依赖项获取pom

回答

1

您可以简单地声明POM本身的依赖关系。

configurations { 
    pom 
} 


dependencies { 
    pom 'org.foo:some-lib:[email protected]' 
} 

task copyPom(type: Copy) { 
    into "${buildDir}/poms" 
    from configurations.pom 
} 
+1

谢谢,但我实际上想从现有的poms中获得依赖关系,而不是用手重构它们。不过,我发现了一个与原始问题完全不同的解决方案。 – user2615350 2014-10-09 07:53:30

+0

您是否找到解决方案? – Cleankod 2017-05-24 07:13:34

0

看看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}" } 
} 

我使用的是相同的API中my plugin in Kotlin