How to uploadArchives with multiple repositories using parameters?

Hello!

So in my gradle project, I want to upload my jar to multiple maven repository, so I do the following:

uploadArchives {
    repositories {
    	mavenLocal()
        mavenDeployer {
            repository(url: maven_repo_1) {
                authentication(userName: maven_user_1, password: maven_password_1)
            }
            repository(url: maven_repo_2) {
                authentication(userName: maven_user_2, password: maven_password_2)
            }
        }
    }
}

My questions are:

  1. Is this the correct way to upload to multiple maven repository at once?
  2. Is there a way to use a parameters to upload to specific maven repository? I.e uploadArchives -r mavenLocal

Note: Previously I had to remove the maven repository and run uploadArchives, I don’t think this is the best practice. However I didn’t find documentation for uploading it with parameters.

Thanks!

  1. This might be a late answer and
  2. probably not exactly what you’re looking for.

But one way to do this is if you specify one repository for releases(say maven_repo_1 is maven_releases), another for snapshots(maven_repo_2 is maven_snapshots), etc,. And then you use any of the gradle release plugins and you will be able to have releases and snapshots on separate repositories depending on whether what you’re uploading is a snapshot or a release.
Something similar to what I have:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "https://<myServer>/repository/maven-releases/") {
                authentication(
                        userName: "$publishUsername",
                        password: "$publishPassword"
                )
            }
            snapshotRepository(url: "https://<myServer>/repository/maven-snapshots/") {
                authentication(
                        userName: "$publishUsername",
                        password: "$publishPassword"
                )
            }
        }
    }
}

Best,
Lumi