Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 947
Jani Avatar asked Mar 24 '15 07:03

Jani


People also ask

Does Gradle generate Pom?

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.

Do we have pom xml in Gradle?

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.

Can Gradle use Maven dependency?

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.


2 Answers

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.

like image 81
Peter Ledbrook Avatar answered Oct 22 '22 19:10

Peter Ledbrook


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)
                }
            }
        }
    }
like image 29
Ravindra-Ravi Verma Avatar answered Oct 22 '22 21:10

Ravindra-Ravi Verma