Gradle 单项目插件管理块不工作(Kotlin DSL)

Gradle single-project pluginManagement block not working (Kotlin DSL)

我需要将多项目构建更改为单项目构建,因为此存储库中只有一个项目。目前,在 settings.gradle 中,我有一个自定义插件回购,目前使用 pluginManagement 块与 resolutionStrategy 和我的回购列表:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == 'com.meanwhileinhell.plugin') {
                useModule('com.meanwhileinhell:gradle-plugin:1.0.0-SNAPSHOT')
            }
        }
    }

    repositories {
        mavenLocal()
        maven { url "https://repo.spring.io/milestone" }
        maven { url "https://plugins.gradle.org/m2/" }

        // Meanwhileinhell repo
        maven {
            url "s3://mvn.meanwhileinhell.com/releases"
            credentials(AwsCredentials) {
                accessKey s3_access_key
                secretKey s3_access_secret
            }
        }
    }

    plugins {
        ...
        ...
    }
}

然而,删除 settings.gradle 并将此块移动到我的 build.gradle.kts (Kotlin DSL) 似乎没有任何作用。我试过用

包装
configurations {
    all {
        resolutionStrategy {
            eachPlugin {
                ...
            }
        }
    }
}

还有

settings {
    pluginManagement {
        resolutionStrategy {
            eachPlugin {
                ...
            }
        }
    }
}

我找到了一个 SO 答案,它使用 settingsEvaluated 来获取 settings 对象,但这同样是不行的。

目前我的 build.gradle.kts 看起来像这样,没有从我的 repo 中提取任何插件:

val springBootVersion: String by project

group = "com.meanwhileinhell.myapp"
version = "$version"

repositories {
    mavenCentral()
    mavenLocal()
    maven ("https://repo.spring.io/snapshot")
    maven ("https://repo.spring.io/milestone")
    maven ("https://plugins.gradle.org/m2/")

    maven {
        url = uri("s3://mvn.meanwhileinhell.com/releases")
        credentials(AwsCredentials::class) {
            accessKey = (project.property("s3_access_key") as String)
            secretKey = (project.property("s3_access_secret") as String)
        }
    }
}

plugins {
    base
    eclipse
    idea
    java
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    // Load but don't apply to root project
    id("org.springframework.boot") version "1.5.14.RELEASE" apply false
}

dependencies {
    ...
}

每当我尝试添加像 id("com.meanwhileinhell.plugin.hell2java") version "1.0.0-SNAPSHOT" 这样的插件 ID 时,我都会收到一个错误,看起来它甚至没有在我的 S3 位置中查找:

* What went wrong:
Plugin [id: 'com.meanwhileinhell.plugin.hell2java', version: '1.0.0-SNAPSHOT'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.meanwhileinhell.plugin.hell2java:com.meanwhileinhell.plugin.hell2java.gradle.plugin:1.0.0-SNAPSHOT')
  Searched in the following repositories:
    Gradle Central Plugin Repository

如有任何帮助,我们将不胜感激!

编辑!!!! ----------------------

我刚刚在 Gradle 文档中找到了这个: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_management

The pluginManagement {} block may only appear in either the settings.gradle file....

看来我完全走错了路,所以将查看初始化脚本路径。

我认为您可能错过了有关文件结构的一些信息。

在 Groovy DSL 中,您有以下文件:

  • build.gradle
  • settings.gradle
  • init.gradle

在 Kotlin DSL 中,您有相同的文件,但扩展名为 .kts:

  • build.gradle.kts
  • settings.gradle.kts
  • init.gradle.kts

Kotlin DSL 在放置内容方面与 Groovy DSL 没有区别。 pluginManagement 需要进入设置文件,所以对于 Kotlin 来说就是 settings.gradle.kts。如果您有疑问,请查看文档。对于几乎所有的代码示例,您都可以在 Groovy 和 Kotlin DSL 之间切换以了解如何操作(以及它们应该进入哪些文件)。