简体   繁体   English

Gradle 6 settings.gradle.kts 属性问题

[英]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.

相关问题 在 settings.gradle.kts 中读取 Gradle 属性 - Reading Gradle properties in settings.gradle.kts Gradle - 属性可以放在 settings.gradle.kts 中吗 - Gradle - Can properties be placed in a settings.gradle.kts 如何定义 settings.gradle.kts 和 build.gradle.kts 中可用的 kotlin dsl gradle 属性? - How to define kotlin dsl gradle properties available in settings.gradle.kts and build.gradle.kts? Gradle 6 迁移 settings.gradle.kts - Gradle 6 migration settings.gradle.kts settings.gradle.kts 的用途是什么? - What is the purpose of settings.gradle.kts? Gradle:在 settings.gradle.kts 和 buildSrc/build.gradle.kts 之间共享存储库配置 - Gradle: share repository configuration between settings.gradle.kts and buildSrc/build.gradle.kts 如何在 buildSrc/build.gradle.kts、settings.gradle.kts 和 build.gradle.kts 中导入辅助类? - How to import a helper class in buildSrc/build.gradle.kts, settings.gradle.kts, and build.gradle.kts? 使用Gradle Kotlin DSL在settings.gradle.kts中设置gradle.ext - Set gradle.ext in settings.gradle.kts with Gradle Kotlin DSL 有没有办法定义要在 gradle 6.0 的 settings.gradle.kts 和项目/子项目 build.gradle.kts 中使用的属性? - Is there a way to define property to be used in both settings.gradle.kts and projects/subprojects build.gradle.kts with gradle 6.0? 在 `settings.gradle.kts` 中使用 `dependencyResolutionManagement` 时,如何在 `gradle.build.kts` 中配置自定义 maven 依赖项? - How does one configure custom maven dependency in `gradle.build.kts` while using `dependencyResolutionManagement` in `settings.gradle.kts`?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM