Properties for initscript block

(Lukas Körfer) #1

I created a Gradle plugin and I want to apply that plugin in an initialization script. In the docs I found the initscript method, which seems to be nothing more but an alias for the regular buildscript method, relying to the source code. Therefor, I understand that the method will always be executed first.

At some point during initialization phase, properties (project / system) are loaded, but I assume that this happens after the initscript closure has been handled. Is there any way to use properties (of any kind) in this closure?

I my case, I try to create a global initialization script for a company and I need to load a plugin inside a initialization script. But I have to use an artifactory server, which is protected by credentials. The credentials should be stored in the user home file. I already tried to access the project properties in every way I can imagine:

initscript {
    repositories {
        maven {
            url 'http://my.local/artifactory/repo'
            credentials.username artifactoryUser
            credentials.password artifactoryPassword
            // Even tried to access directly via startParameter.projectProperties['artifactoryUser'] (or systemPropertiesArgs)

The corresponding file:


Of course, I added the systemProp. prefix when trying to access them as system properties.

(James Justinic) #2

You always have the option of manually loading the specific property file you need in your init script:

// Load
Properties properties = new Properties()
properties.load(new File(getGradleUserHomeDir(), '').newDataInputStream())

// Access

(Lukas Körfer) #3

Yeah, I aready thought of that solution, but, to be honest, I did not really like it. Now, since it seems like a better solution does not exist, I decided to also use the Java Properties class, but to load a new file to avoid problems when accessing

Nevertheless, thank you very much for your efforts and the confirmation, that no better solution exists.