gradle - Gradle 单项目插件管理块不起作用(Kotlin DSL)
问题描述
我需要将多项目构建更改为单项目构建,因为在这个 repo 中只有一个项目。目前,在 中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 {
...
}
}
}
}
我找到了一个用于settingsEvaluated
获取settings
对象的 SO 答案,但这又是不行的。
目前我build.gradle.kts
看起来像这样,没有从我的仓库中提取任何插件:
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") version "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 文档中找到了这个: https ://docs.gradle.org/current/userguide/plugins.html#sec:plugin_management
pluginManagement {} 块只能出现在 settings.gradle 文件中...。
看起来我完全走错了路,所以将研究初始化脚本路线。
解决方案
我想你可能错过了一些关于文件结构的东西。
在 Groovy DSL 中,您有以下文件:
- 构建.gradle
- 设置.gradle
- 初始化.gradle
在 Kotlin DSL 中,您拥有相同的文件,但扩展名为 .kts:
- 构建.gradle.kts
- settings.gradle.kts
- 初始化.gradle.kts
Kotlin DSL 与 Groovy DSL 的放置位置没有什么不同。pluginManagement
需要进入设置文件,所以对于 Kotlin 来说就是settings.gradle.kts
. 如果您有疑问,请查看文档。对于几乎所有的代码示例,您都可以在 Groovy 和 Kotlin DSL 之间切换以查看如何操作(以及它们应该进入哪些文件)。
推荐阅读
- matlab - 在 Matlab 中重新创建 Zadoff-Chu 的循环自相关图
- asp.net-mvc - 表单提交带有必填字段的 DropDownListFor
- hive - 无法从配置单元中的现有表创建视图
- c# - 有哪些方法可以优化非分代 GC 的标记阶段?
- php - stream_socket_sendto():连接被拒绝
- javascript - 更改属性时按钮未提交
- java - Spark/Java:不可序列化问题 - Kryo 序列化
- php - Laravel - Elasticsearch ClientBuilder 未找到
- python - 将 Numpy 数组中的所有行对相乘
- arrays - 从 JMSByte 消息中提取值