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

Gradle单项目插件管理块不工作(Kotlin DSL),gradle,gradle-plugin,gradle-kotlin-dsl,Gradle,Gradle Plugin,Gradle Kotlin Dsl,我需要将一个多项目构建更改为一个项目构建,因为在这个回购协议中存在并且永远只有一个项目。目前,在settings.gradle中,我有一个自定义的插件repo,它当前使用pluginManagement块和resolutionStrategy以及我的repo列表: pluginManagement { resolutionStrategy { eachPlugin { if (requested.id.namespace == 'com.meanw

我需要将一个多项目构建更改为一个项目构建,因为在这个回购协议中存在并且永远只有一个项目。目前,在
settings.gradle
中,我有一个自定义的插件repo,它当前使用
pluginManagement
块和
resolutionStrategy
以及我的repo列表:

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答案,它使用
settingsevaluate
来获取
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,如
id(“com.meanwhileinhell.plugin.hell2java”)版本“1.0.0-SNAPSHOT”
时,我都会收到一个错误,看起来它甚至不在我的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文档中发现了这一点:

pluginManagement{}块只能出现在settings.gradle文件中的任何一个


看起来我完全走错了方向,所以我将研究初始化脚本路线。

我认为您可能遗漏了有关文件结构的某些内容

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

  • 格雷德尔先生
  • 格雷德尔酒店
  • 初始梯度
在Kotlin DSL中,您有相同的文件,但扩展名为.kts:

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

Kotlin DSL与Groovy DSL在放置东西的位置上没有区别
pluginManagement
需要进入设置文件,因此对于Kotlin,这将是
settings.gradle.kts
。如果您有疑问,请查看文档。对于几乎所有的代码示例,您都可以在Groovy和Kotlin DSL之间切换,看看如何操作(以及它们应该进入哪些文件)。

谢谢您的评论@BjørnVester。
settings.gradle[.kts]
文件不是只用于多项目构建吗?我一直都有它,即使是独立项目。通过它可以更改的另一项内容是项目名称(如果您不想依赖默认的文件夹名称)。