gradle:如何共享一个build.gradle,其中包含我唯一拥有的信息?

fge*_*fge 2 sonatype gradle build.gradle

我的build.gradle文件包含这样的部分,用于将存档上传到SonaType:

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

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

            pom.project {
                // etc etc
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在标记的点上HERE,其他希望使用我的构建文件的用户将失败,因为至少没有定义第一个变量:

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
Run Code Online (Sandbox Code Playgroud)

如何修改上面的部分,以便用户不受这些未定义的变量的影响?

jud*_*ole 9

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

例如:

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

sonatypeUsername=
sonatypePassword=
Run Code Online (Sandbox Code Playgroud)

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

编辑:今天我不会这样做.按照Gradle指南,使用required.正如@ jb-nizet Gradle参考53.3.3条件签名的例子:http://www.gradle.org/docs/current/userguide/signing_plugin.html