2

Yesterday I upgraded Android Studio to Arctic Fox, which moves from Gradle 6 to 7. Gradle 7 removes the 'maven' plugin, which my team had been using to package an Android Library we had into an AAR file as part of an automated/CI build.

Previously in our library's build.gradle file we had

apply plugin: 'maven'
...
android {
 // normal android library stuff here
}
...
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "file://$projectDir/deploy")
        }
    }

}

The outcome of this was we could run gradle uploadArchives, and a nice maven directory structure would be output into the $projectDir/deploy folder. Our CI system could pick this up and distribute it, and all was well.

(For reference, it looked like this, which I hope to reproduce with Gradle 7)

deploy/
  com/
    mycompany/
      mylibrary/
        maven-metadata.xml
        maven-metadata.xml.sha1
        1.0.0/
          mylibrary.aar
          mylibrary.aar.sha1
          mylibrary-1.0.0.pom
          mylibrary-1.0.0.pom.sha1

(.md5 files are in there as well, but not important)

However, Gradle 7 removes all these things and tells us to use the maven-publish plugin, which I cannot get to work.

This is my current best effort, based on Google's page here

apply plugin: 'maven-publish'
...
android {
 // normal android library stuff here
}
...
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
            }
            debug(MavenPublication) {
                from components.debug
            }
        }
    }
    repositories {
        maven {
            url = layout.buildDirectory.dir('deploy')
        }
    }
}

However, when to run this, it doesn't produce the desired output. Here's the output from ./gradlew --info publish:

> Task :mylibrary:publish UP-TO-DATE
Skipping task ':mylibrary:publish' as it has no actions.
:mylibrary:publish (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.

When I run ./gradlew --info publishRelease, then it logs a lot more, and actually does compile the library, however it doesn't "publish" it. I end up with a directory structure like this:

mylibrary/
  build/
    publications/
      release/
        pom-default.xml
        module.json
    outputs/
      aar/
        mylibrary-release.aar

There is no deploy folder, and no versioned maven folder hierarchy.

Help please? The internet is full of complex gradle docs talking about the maven-publish plugin, but none are targeted at Android, and none seem to work in the context of an Android library.

Orion Edwards
  • 121,657
  • 64
  • 239
  • 328

1 Answers1

3

After much banging around, I managed to resolve it with the following gradle configuration:

apply plugin: 'maven-publish'
...
android {
 // normal android library stuff here
}
...
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
            }
            debug(MavenPublication) {
                from components.debug
            }
        }
        // note repositories goes under publishing
        repositories {
            maven {
                url = "file://$projectDir/deploy"
            }
        }
    }
}

After this change, you need to run gradle publishReleasePublicationToMavenRepository rather than uploadArchives and then it works.

Orion Edwards
  • 121,657
  • 64
  • 239
  • 328