英文:
Gradle 6 settings.gradle.kts properties problem
问题
请帮助我理解在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
}
}
}
}
现在我遇到了一个错误:"Unresolved reference: artifactoryUser"。
这个问题可以通过将属性声明移动到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
}
}
}
}
但我不明白为什么会这样。
英文:
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.
答案1
得分: 5
这是关于它的原因在Grade 6升级说明中提到:
> 在设置脚本中的pluginManagement块现在被隔离
>
> 以前,在设置脚本中的任何pluginManagement {}块在脚本的正常执行期间都会被执行。
>
> 现在,它们在类似于buildscript {}或plugins {}的方式下更早执行。这意味着在这样的块内部的代码不能引用脚本中其他地方声明的内容。
>
> 这个改变是为了在解析设置脚本本身的插件时也可以应用pluginManagement配置。
英文:
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.
答案2
得分: 1
将 val
移动到 pluginManagement 块内部可以解决问题,从 Gradle 5.x 迁移到 Gradle 6.x 时。
pluginManagement {
val kotlinVersion: String by settings
...
}
英文:
Indeed, moving the val
inside the pluginManagement block does the trick, when migrating from Gradle 5.x to Gradle 6.x.
val kotlinVersion: String by settings
pluginManagement {
...
}
to:
pluginManagement {
val kotlinVersion: String by settings
...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论