Skip to content

Instantly share code, notes, and snippets.

@prasad79
Last active December 30, 2019 17:32
Show Gist options
  • Save prasad79/234152493e6f79c107802dc4bcec63fc to your computer and use it in GitHub Desktop.
Save prasad79/234152493e6f79c107802dc4bcec63fc to your computer and use it in GitHub Desktop.
publish Android library to Github Packages - generate POM file with Transitive dependencies
publications {
bar(MavenPublication) {
groupId getGroupId()
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
//generate .pom file with transitive dependencies
pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return
final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)
if (!dep.transitive) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment