[英]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):请帮助我了解 Gradle 6 中的更改,因此以下代码不再起作用(在 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".现在我有一个错误:“未解决的引用:artifactoryUser”。
This problem can be solved by moving properties declaration inside the pluginManagement block这个问题可以通过在 pluginManagement 块中移动属性声明来解决
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.但我不明白为什么。
The reason for it is mentioned in the Grade 6 upgrade notes :原因在Grade 6升级说明中提到:
The pluginManagement block in settings scripts is now isolated
设置脚本中的 pluginManagement 块现在是隔离的
Previously, any pluginManagement {} blocks inside a settings script were executed during the normal execution of the script.
以前,设置脚本中的任何 pluginManagement {} 块都是在脚本正常执行期间执行的。
Now, they are executed earlier in a similar manner to buildscript {} or plugins {}.
现在,它们以类似于 buildscript {} 或 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.
已进行此更改,以便在解析设置脚本本身的插件时也可以应用 pluginManagement 配置。
Indeed, moving the val
inside the pluginManagement block does the trick, when migrating from Gradle 5.x to Gradle 6.x.实际上,当从 Gradle 5.x 迁移到 Gradle 6.x 时,将
val
移动到 pluginManagement 块中就可以了。
val kotlinVersion: String by settings
pluginManagement {
...
}
to:到:
pluginManagement {
val kotlinVersion: String by settings
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.