I'm using the maven-publish plugin to publish an aar file to a maven repository. However I noticed that compile dependencies are not added to the pom.xml even after I add the transitive property. I'm using com.android.tools.build:gradle:1.1.3
Any hints on how to resolve this ?
build.gradle
publishing {
publications {
sdkAar(MavenPublication) {
artifacts {
groupId 'com.test'
artifactId 'my_sdk'
version currentVersion
artifact 'build/outputs/aar/release.aar'
artifact androidJavadocsJar {
classifier "javadoc"
}
}
}
sdkJar(MavenPublication) {
groupId 'com.test'
artifactId 'my_sdk_jar'
version currentVersion
artifact 'build/libs/release.jar'
artifact androidJavadocsJar {
classifier "javadoc"
}
}
}
repositories {
maven {
credentials {
username archiva_username
password archiva_password
}
}
}
}
Thanks in Advance
We already saw that Gradle added a generatePom<publicationName> task to our project. Furthermore, we can define some properties of the POM file inside a publication configuration. Gradle also offers a hook to customize the generated POM file even further.
It uses a declarative XML file for its POM file and has a host of plugins that you can use. Gradle uses the directory structure you see on Maven, but this can be customized.
Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project.
If you want the dependencies to be added automatically to the POM, you need to use the components feature. Here's an example from the user guide:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
That from ...
is important. What I don't know is whether the Android plugin sets up its own software components. I can't see any references to such things.
Remember that the new publishing mechanism is currently incubating, and perhaps that's why the Android plugin doesn't offer any direct support for it at the moment.
If you really want to use the publishing plugin, you can grab the runtime dependencies of your artifacts and manually add them to the POM using the syntax described in the user guide. I wouldn't recommend that approach though as it's messy and looks error prone.
dependency not added automatically you need to add publishing tag.
publishing {
publications {
aar(MavenPublication) {
groupId libraryGroupId
version = libraryVersion
artifactId libraryArtifactId
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)
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With