Gradle not including dependencies in published pom.xml

android, gradle, maven, pom.xml

Solution

I was able to work around this by having the script add the dependencies to the pom directly using `pom.withXml`.

//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')

    //Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
    configurations.compile.allDependencies.each {
        def dependencyNode = dependenciesNode.appendNode('dependency')
        dependencyNode.appendNode('groupId', it.group)
        dependencyNode.appendNode('artifactId', it.name)
        dependencyNode.appendNode('version', it.version)
    }
}

This works for my project, it may have unforeseen consequences in others.

Problem

I have a Gradle project I'm using the maven-publisher plugin to install my android library to maven local and a maven repo. That works, but the generated pom.xml does not include any dependency information. Is there a workaround to include that information, or am I forced to go back to the maven plugin and do all the manual configuration that requires? Researching I realized that I'm not telling the publication where the dependencies are, I'm only specifying the output/artifact, so I need a way to link this `MavenPublication` to the dependencies, but I have not yet found how to do that in the documentation. ``` ------------------------------------------------------------ Gradle 1.10 ------------------------------------------------------------ Build time: 2013-12-17 09:28:15 UTC Build number: none Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6 Groovy: 1.8.6 Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013 Ivy: 2.2.0 JVM: 1.7.0_60 (Oracle Corporation 24.60-b09) OS: Mac OS X 10.9.2 x86_64 ``` Relevant build.gradle sections ``` //... apply plugin: 'android-library' apply plugin: 'robolectric' apply plugin: 'maven-publish' //... repositories { mavenLocal() maven { name "myNexus" url myNexusUrl } mavenCentral() } //... android.libraryVariants publishing { publications { sdk(MavenPublication) { artifactId 'my-android-sdk' artifact "${project.buildDir}/outputs/aar/${project.name}-${project.version}.aar" } } repositories { maven { name "myNexus" url myNexusUrl credentials { username myNexusUsername password myNexusPassword } } } } ``` Generated pom.xml: ``` <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.example.android</groupId> <artifactId>my-android-sdk</artifactId> <version>gradle-SNAPSHOT</version> <packaging>aar</packaging> </project> ```

Original source