我正在使用maven-publish
中的build.gradle
插件。对于每个compile
依赖项,group
,name
和version
用于在生成的pom.xml
文件中生成相应的标记 - 这样可以正常工作
以下是我的示例依赖项:
dependencies {
compile (
[group: 'com.actionbarsherlock', name: 'actionbarsherlock', version: '4.4.0', ext: 'aar'],
[group: 'com.android.support', name: 'support-v4', version: '19.0.+']
)}
这是我的发布元素:
publishing {
publications {
// A publication named 'mavenAndroid'
mavenPublishLibrary(MavenPublication) {
// Artifact using the aar from the build output
artifact "${project.projectDir}/build/outputs/aar/${project.name}-${project.version}.aar"
// Generate dependencies manually for POM
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies, adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
// This is what I'd want to do...
if (it.ext != '') {
dependencyNode.appendNode('type', it.ext)
}
// ...but this doesn't work!
}
}
}
}
}
我希望能够将ext
值(例如aar
)与pom.xml
,group
和{name
一起添加到version
{1}},就像我在上面代码段中所拥有的那样。
答案 0 :(得分:2)
当我经历了几个小时的挣扎时,我会问这些问题,然后我总是在问完后不久就回答自己!
我使用以下内容获取依赖项扩展,替换问题中的if()
:
it.getArtifacts().each {
dependencyNode.appendNode('type', it.getExtension())
}