2

My build.gradle file contains a section like this to upload archives to SonaType:

uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment {
                MavenDeployment deployment -> signing.signPom(deployment);
            }

            // HERE
            repository(url: sonatypeRepoURI) { 
                authentication(userName: sonatypeUsername,
                    password: sonatypePassword);
            }

            pom.project {
                // etc etc
            }
        }
    }
}

At the point marked HERE, other users wishing to use my build file will fail, because at least the first variable is not defined:

FAILURE: Build failed with an exception.

* Where:
Build file '/path/to/build.gradle' line: 144

* What went wrong:
A problem occurred evaluating root project 'whateverTheProject'.
> No such property: sonatypeRepoURI for class: 
  org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

How do I modify the section above so that users are not affected by these variables not being defined for them?

4

2 回答 2

9

您可以尝试将所有需要的属性添加到您添加到版本控制的gradle.properties文件中,但将值留空。

例如:

version=1.0
signing.keyId=
signing.password=
signing.secretKeyRingFile=

sonatypeUsername=
sonatypePassword=

然后你在你自己的${USER}/.gradle/gradle.properties中覆盖这些。作为一个例子,看看一个工作项目https://github.com/judoole/monitorino。应该能够在任何机器上运行除快照阶段构建之外的所有任务。

编辑:我今天不会这样做。遵循 Gradle 指南,使用 required。正如@jb-nizet Gradle ref 53.3.3 Conditional Signing 中的示例:http: //www.gradle.org/docs/current/userguide/signing_plugin.html

于 2013-06-26T08:39:43.763 回答
1

非常简单,只需在“~/.gradle”中创建“gradle.properties”文件,内容如下:

sonatypeUsername=
sonatypePassword=

运行您的项目后。它运行正常。

于 2015-04-02T05:44:44.457 回答