gradle: how to share a build.gradle which contains information I am the only one to have?

StackOverflow https://stackoverflow.com/questions/17311070

  •  01-06-2022
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

You could try to add all the needed properties to your gradle.properties file, which you add to version control, but leave the values empty.

Eg:

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

sonatypeUsername=
sonatypePassword=

Then you override these in your own ${USER}/.gradle/gradle.properties. As an example take a look at a working project https://github.com/judoole/monitorino. Should be able to run all tasks at any machine except snapshot, stage and build.

Edit: I would not do it like this today. Follow the Gradle guide, using required. Just as the example from @jb-nizet Gradle ref 53.3.3 Conditional Signing: http://www.gradle.org/docs/current/userguide/signing_plugin.html

他のヒント

Very simple just create the "gradle.properties" file in "~/.gradle" with the following contents:

sonatypeUsername=
sonatypePassword=

After run your project. Its running properly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top