4

I am trying to setup a gradle 5 project which uses a custom plugin someone developed and is available in my company internal repository.

Until now, we have been importing it using the following approach:

buildscript {
    ext {
        usr = System.env.usr != null ? System.env.usr : project.ext.properties.usr
        pass = System.env.pass != null ? System.env.pass : project.ext.properties.pass

        privateRepo = {
            name "privateRepo"
            url <url>
            credentials {
                username usr
                password pass
            }
        }
    }

    repositories {
        maven (privateRepo)
    }

    dependencies {
        // various dependencies
        classpath "org.something:some-plugin:1.0"
        ...
    }

apply plugin: "someplugin"

Just like this question. As far as I understood, this is a deprecated approach, so I would like to use the pluginManagement block gradle.settings (again, as suggested in this answer)

The problem is that my repository is private, so I would need to define the user and pass variables.

I tried similar approached inside the pluginManagement block in gradle.settings, but I could not get it to work: the pluginManagement does not support the ext block and the pluginManagement has to be the first block in the script, limiting my alternatives.

Is there anyway I can define the variables so it can be used in the pluginManagement block?

Disclaimer: my question is not a duplicated of the linked one because my problem is related to the credentials part, that I am having issues defining the variables and values.

JSBach
  • 4,679
  • 8
  • 51
  • 98

1 Answers1

0

Well I just added the def inside the block, not ideal but at least works:

pluginManagement {

    def artifactoryUrl = "www.my.artifactory.url"
    def artifactoryUser= "myUser"
    def artifactoryPass= "myPass"

    repositories {
            maven {
                name = "A-MavenGoogle"
                url = uri(
                        "https://$artifactoryUrl/list/maven-google-remote/"
                )
                credentials {
                    username = artifactoryUser
                    password = artifactoryPass
                }
            }
            maven {
                name = "A-MavenCentral"
                url = uri(
                        "https://$artifactoryUrl/list/maven-central-remote/"
                )
                credentials {
                    username = artifactoryUser
                    password = artifactoryPass
                }
            }
     }
}
htafoya
  • 18,261
  • 11
  • 80
  • 104