3

I have an Android library (gradle multi module project) where I publish to two different Nexus Maven2 repositories with strict versioning, a release repository and a snapshot repository. This has worked well using Android Gradle Plugin 4.0.1.

command:

gradlew -PmavenRepoUrl=https://myserver.com/nexus/repository/project-snapshots -PmavenRepoCredentialType=PasswordType -PmavenUser=$NEXUS_USER -PmavenPassword=$NEXUS_PASSWORD publishDebugPublicationToMavenRepository

build.gradle.kts:

plugins {
    id("com.android.library")
    id("maven-publish")
    ...
}

val mavenRepoUrl: String by project
val mavenRepoCredentialType: String by project
val mavenPublicAccessKey: String by project
val mavenPublicSecretKey: String by project
val mavenUser: String by project
val mavenPassword: String by project
afterEvaluate {
    publishing {
        repositories {
            maven(url = mavenRepoUrl) {
                when (mavenRepoCredentialType) {
                    "AwsCredentialType" -> {
                        credentials(AwsCredentials::class) {
                            accessKey = mavenPublicAccessKey
                            secretKey = mavenPublicSecretKey
                        }
                    }
                    "PasswordType" -> {
                        credentials(PasswordCredentials::class) {
                            username = mavenUser
                            password = mavenPassword
                        }
                    }
                    else -> {
                        logger.log(ERROR, "Unsupported credential type: $mavenRepoCredentialType")
                    }
                }
            }
        }
        publications {
            create<MavenPublication>("Release") {
                from(components.getByName("release"))
                groupId = project.group as String
                artifactId = "my-android-project-${project.name}"
                version = project.version as String
            }
            create<MavenPublication>("Debug") {
                from(components.getByName("debug"))
                groupId = project.group as String
                artifactId = "my-android-project-${project.name}"
                version = project.version as String
            }
        }
    }
}

But after updating to Android Gradle Plugin 7.0+ I'm getting this error:

Execution failed for task ':core:publishDebugPublicationToMavenRepository'.
> Failed to publish publication 'Debug' to repository 'maven'
   > Could not PUT 'https://myserver.com/nexus/repository/project-snapshots/com/myproject/1.1.0-M25/my-project-1.1.0-M25.aar'. Received status code 400 from server: Repository version policy: SNAPSHOT does not allow version: 1.1.0-M25

(When upgrading Android Gradle Plugin I had to remove the "isDebuggable" attribute from the build variants. Maybe that's a clue?).

To troubleshoot I tried explicitly setting the version to "-SNAPSHOT" for debug builds, build.gradle.kts:

        publications {
            create<MavenPublication>("Debug") {
                ...
                version = (project.version as String) + "-SNAPSHOT"
                ...
            }
        }

but then I get this error:

* What went wrong:
Could not determine the dependencies of task ':my-module-2:publishDebugPublicationToMavenRepository'.
> Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.
  Found the following publications in project ':my-modulue':
    - Maven publication 'Release' with coordinates com.myproject:my-module:1.1.0-M25
    - Maven publication 'Debug' with coordinates com.myproject:my-module:1.1.0-M25-SNAPSHOT

(related: https://github.com/gradle/gradle/issues/12324)

My setup:

  • Multi module project with Android library modules
  • Android Gradle Plugin 7.0.1
  • Gradle 7.0.2, 7.1.1, 7.2 (doesn't work with any of them)
  • Kotlin Gradle DSL

Is this a regression caused by the Android Gradle Plugin or is there a way to solve my problem?

Alix
  • 2,630
  • 30
  • 72

0 Answers0