简体   繁体   English

Gradle 6 迁移 settings.gradle.kts

[英]Gradle 6 migration settings.gradle.kts

I've got the following code in the settings.gradle.kts , which is works fine in gradle 5我在settings.gradle.kts中有以下代码,在gradle 5中运行良好

rootProject.name = "server"

val pluginsRepoUrl: String by settings
val repoUsername: String by settings
val repoPassword: String by settings

pluginManagement {
    repositories {
        maven {
            url = uri(pluginsRepoUrl)
            credentials {
                username = repoUsername
                password = repoPassword
            }
        }
    }
}

I want to upgrade to gradle 6 but this code is not works and gives me a following error:我想升级到gradle 6 ,但这段代码不起作用,并出现以下错误:

e: .../settings.gradle.kts:10:23: Unresolved reference: pluginsRepoUrl

The values comes from the gradle.properties file.这些值来自gradle.properties文件。

In Gradle 6, the behavior of the pluginManagement {} block was changed :在 Gradle 6 中, 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.这意味着此类块内的代码不能引用脚本中其他地方声明的任何内容。

(emphasis mine) (强调我的)

This means that you cannot reference the variables declared outside of that block.这意味着您不能引用在该块之外声明的变量。 To fix this, move those declarations inside the pluginManagement {} block:要解决此问题,请将这些声明移到pluginManagement {}块中:

pluginManagement {
    val pluginsRepoUrl: String by settings
    val repoUsername: String by settings
    val repoPassword: String by settings
    repositories {
        ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gradle 6 settings.gradle.kts 属性问题 - Gradle 6 settings.gradle.kts properties problem 在 settings.gradle.kts 中读取 Gradle 属性 - Reading Gradle properties in settings.gradle.kts settings.gradle.kts 的用途是什么? - What is the purpose of 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:在 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