Jani
Jani

Reputation: 1490

Dependencies not added to POM file - Android Gradle Maven Publishing

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

Upvotes: 13

Views: 4823

Answers (3)

Nguyen Phuc
Nguyen Phuc

Reputation: 57

please try this code, I tried it successfully.

//generate pom nodes for dependencies
            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')
                configurations.implementation.allDependencies.each { dependency ->
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', dependency.group)
                    dependencyNode.appendNode('artifactId', dependency.name)
                    dependencyNode.appendNode('version', dependency.version)
                }
            }

Upvotes: 0

Ravindra-Ravi Verma
Ravindra-Ravi Verma

Reputation: 535

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)
                }
            }
        }
    }

Upvotes: 1

Peter Ledbrook
Peter Ledbrook

Reputation: 4462

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.

Upvotes: 4

Related Questions