Publish each Android library flavour to it's own repository

29 Views Asked by At

I'm trying to publishes diffrent flavours of my library to diffrent repositories. I'm using the maven-publish plugin for this. I have an Android library with multiple flavours

flavorDimensions += "version"
productFlavors {
    create("external") {
        dimension = "version"
    }
    create("internal") {
        dimension = "version"
    }
}

I've create two publishing variants for the library

publishing {
    singleVariant("externalRelease")
    singleVariant("internalRelease")
}

Then i setup the publications and repositories

afterEvaluate {
val releaseVersion = "1.0.10"
publishing {
    publications {
        register<MavenPublication>("internalRelease") {
            groupId = "com.company"
            artifactId = "internal"
            version = releaseVersion

            afterEvaluate {
                from(components["internalRelease"])
            }
        }
        register<MavenPublication>("externalRelease") {
            groupId = "com.company"
            artifactId = "external"
            version = releaseVersion

            afterEvaluate {
                from(components["externalRelease"])
            }
        }
    }
    repositories {
        maven {
            name = "internal"
            url = uri("https://urltomyinternal")
            authentication {
                create<BasicAuthentication>("basic")
            }
            credentials {
                username = project.properties["mavenUsername"].toString()
                password = project.properties["mavenPassword"].toString()
            }
        }
        maven {
            name = "external"
            url = uri("https://urltomyexternal")
            authentication {
                create<BasicAuthentication>("basic")
            }
            credentials {
                username = project.properties["mavenUsername"].toString()
                password = project.properties["mavenPassword"].toString()
            }
        }
    }
}

} Now my problem is that both publications gets published to both of the repositories. What i want is for the internalRelease to get published to the internal repository and externalRelease to the external.

1

There are 1 best solutions below

0
user2408952 On

Running ./gradlew tasks gave me a list of visible task. I spotted i had the two tasks i was looking for which where ./gradlew publishInternalReleasePublicationToInternalRepository and ./gradlew publishExternalReleasePublicationToExternalRepository