When you want to publish your library, there are two ways to do it.
- Using artifact()
publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
artifactId project.getName()
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.getByName("_releaseCompile").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.moduleGroup)
dependency.appendNode('artifactId', it.moduleName)
dependency.appendNode('version', it.moduleVersion)
}
}
}
}
}
- Using components:
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId = "com.app.core"
artifactId = project.name
version = "1.0.1"
from components.release
}
}
artifactoryPublish {
publications(publishing.publications.release)
}
}
}
I read some blog posts and they mention that pom.withXml needs to be included in order to include the transitive dependencies. i.e if your library uses a third party dependency, then it will not included if you don't use the pom.withXml section and app will crash on runtime.
When you use components definition, it automatically includes the transitive dependencies. I couldn't find any documentation on usage of these APIs. What is actually the components definition is doing? What is the difference between using components and artifact definitions?