Auto generated pom.xml from uploadArchives task is missing dependencies after moving to gradle 1.11

Hello, I just moved from gradle 1.10 to 1.11. In my team’s project, we are using the ‘maven’ plugin and ‘uploadArchives’ task to upload the assembled aar artifact to our maven repository. Everything was working fine until we moved to gradle 1.11 at which point the pom file generated by ‘uploadArchives’ was missing the entire dependencies section.

Here is a snippet of the build.gradle:

apply plugin: 'android-library'
apply plugin: 'maven'
  dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    compile group:'depgroup2', name:'departifact2', version: '1.+'
}
  ....
  uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: <our maven repo URL>)
             pom.groupId = 'group1'
            pom.version = 'version1'
            pom.artifactId = 'artifact1'
        }
    }
}

The generated pom from gradle 1.10 is below(expected output with dependencies):

<?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>group1</groupId>
  <artifactId>artifact1</artifactId>
  <version>version1</version>
  <packaging>aar</packaging>
  <dependencies>
       <dependency>
      <groupId>depgroup2</groupId>
      <artifactId>departifact2</artifactId>
      <version>1.+</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

However, with no other changes other than switching to gradle 1.11, the dependencies block is missing:

<?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>group1</groupId>
  <artifactId>artifact1</artifactId>
  <version>version1</version>
  <packaging>aar</packaging>
</project>

What I found from trying several things is that if I do not set a custom value on any of the pom objects in build.gradle (pom.groupId, pom.version, pom.artifactId), then the dependencies block shows up. If I set any of them, the dependencies block disappears. Is this a known issue in 1.11?

I added a test task as below to build.gradle:

task createPom << {
    pom {
        project {
            groupId 'alvingroup'
            artifactId 'alvinartifact'
            version '1.0.0'
          }
    }.writeTo("pom.xml")
}

When I look at the generated pom.xml, all the dependencies are there(indicating pom object can be changed just fine) so maybe this is a specific problem with the uploadArchives task when changing the pom object properties?

Same here, this used to work. Using 1.10 and Android’s plugin 0.9.

Changing the plugin level down to 0.8.+ brought the pom.xml dependencies back, I opened an issue in the Android project:

https://code.google.com/p/android/issues/detail?id=67064

this is not fixed in 0.9.1 as stated in the linked issue above.

This will be fixed in the next release of the android tools. The solution for now is to wrap the uploadArchives config in ‘afterEvaluate {}’.

afterEvaluate {
  uploadArchives {
      repositories {
          mavenDeployer {
              repository(url: <our maven repo URL>)
               pom.groupId = 'group1'
              pom.version = 'version1'
              pom.artifactId = 'artifact1'
          }
      }
  }
}

we’re not using uploadArchives as such, we’re using install,

task install(type: Upload) {
  setConfiguration configurations.getByName("archives")
  repositories {
    mavenInstaller()
  }
}

any workaround?

The issue is still not fixed in the latest android gradle build tools 0.11.+.

I am still facing same issue with recent version of gradle 2.0.

This was indeed a good solution and worked for me, Thanks a lot Luke.

Btw, I have tried with multiple version of gradle as per Alvin but it did not work.

same here with 2.2