简体   繁体   English

如何使用 Gradle 中的参数上传具有多个存储库的档案?

[英]How to uploadArchives with multiple repositories using parameters in Gradle?

In my gradle project, I want to upload my jar to multiple maven repository, so I do the following:在我的 gradle 项目中,我想将我的 jar 上传到多个 maven 存储库,因此我执行以下操作:

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 question is:我的问题是:

  1. Is this the correct way to upload to multiple maven repository at once?这是一次上传到多个 Maven 存储库的正确方法吗?
  2. Is there a way to use a parameters to upload to specific maven repository?有没有办法使用参数上传到特定的 Maven 存储库? Ie uploadArchives -r mavenLocaluploadArchives -r mavenLocal

Note: Previously I had to remove the maven repository and run uploadArchives , I don't think this is the best practice.注意:以前我必须删除 maven 存储库并运行uploadArchives ,我认为这不是最佳实践。 However I didn't find documentation for uploading it with parameters.但是我没有找到上传参数的文档。

What you could do, is using a project property to pick the right configuration.您可以做的是使用项目属性来选择正确的配置。

For example, if you want to deploy to a remote repository by default, but with a parameter that switches to a local repo:例如,如果您想默认部署到远程存储库,但使用切换到本地存储库的参数:

uploadArchives {
    repositories {
        if (project.hasProperty('localRepoPath')) {
            mavenDeployer {
                repository(url: uri(project.getProperty('localRepoPath')))
                ...
            }
        } else {
            mavenDeployer {
                repository(url: maven_repo_1)
                ...
            }
        }
    }
}

Then, to invoke:然后,调用:

# Local upload
./gradlew uploadArchives -PlocalRepoPath=/tmp/maven

# Public upload
./gradlew uploadArchives

You can adapt this approach to your own needs.您可以根据自己的需要调整此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM