Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 6 settings.gradle.kts properties problem

please help me understand what was changed in Gradle 6 so the following code doesn't work anymore (worked well in Gradle 5):

val artifactoryUser: String by settings
val artifactoryPassword: String by settings

pluginManagement {
    repositories {
        mavenLocal()
        maven {
            url = uri("https://internal-artifactory")
            credentials {
                username = artifactoryUser
                password = artifactoryPassword
            }
        }
    }
}

Now I have an error: "Unresolved reference: artifactoryUser".

This problem can be solved by moving properties declaration inside the pluginManagement block

pluginManagement {
val artifactoryUser: String by settings
val artifactoryPassword: String by settings
    repositories {
        mavenLocal()
        maven {
            url = uri("https://internal-artifactory")
            credentials {
                username = artifactoryUser
                password = artifactoryPassword
            }
        }
    }
}

But I don't understand why.

like image 713
c0nsigliere Avatar asked Jan 06 '20 13:01

c0nsigliere


People also ask

Should I use buildSrc?

buildSrc should be preferred over script plugins as it is easier to maintain, refactor and test the code. buildSrc uses the same source code conventions applicable to Java and Groovy projects. It also provides direct access to the Gradle API.

Do I need settings Gradle?

The framework requires the existence of the settings. gradle in a multi-project build, while it's optional for a single-project build. and Gradle is calling the void include(String… projectPaths) method on the Settings instance when creating the build.


1 Answers

The reason for it is mentioned in the Grade 6 upgrade notes :

The pluginManagement block in settings scripts is now isolated

Previously, any pluginManagement {} blocks inside a settings script were executed during the normal execution of the script.

Now, they are executed earlier in a similar manner to buildscript {} or plugins {}. This means that code inside such a block cannot reference anything declared elsewhere in the script.

This change has been made so that pluginManagement configuration can also be applied when resolving plugins for the settings script itself.

like image 107
Bjørn Vester Avatar answered Sep 18 '22 22:09

Bjørn Vester