gradle - 具有自定义组 ID 的 Gradle 插件
问题描述
摇篮 6.1
我很难在 Gradle 中使用新的插件配置模式和来自自定义存储库的自定义插件。
buildscript {
repositories {
maven {
url = uri("https://custom")
}
mavenCentral()
jcenter()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
}
plugins {
java
idea
id("com.custom.gradle.plugin.myplugin") version "1.1.0"
}
我收到此错误:
Plugin [id: 'com.custom.gradle.plugin.myplugin', version: '1.1.0'] 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.custom.gradle.plugin.myplugin:com.custom.gradle.plugin.myplugin:1.1.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Gradle 将使用插件 ID 作为其组 ID。
如果我使用旧方法,它会起作用:
buildscript {
repositories {
maven {
url = uri("https://custom")
}
mavenCentral()
jcenter()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("com.custom:com.custom.gradle.plugin.myplugin:1.1.0")
}
}
apply(plugin = "com.custom.gradle.plugin.myplugin")
有没有办法用 'id' 命令指定组 id?还是我违反了插件定义与那个旧插件的合同?
解决方案
为了使用更新/首选plugins { }
的 DSL,自定义插件必须发布插件标记工件。
如果自定义插件可以修改,那么我建议更新以使用Java Gradle Plugin Development 插件,该插件将为您创建标记。
如果插件无法更新,那么您仍然可以使用该plugins { }
块,但您需要手动解析插件:
在主要build.gradle
:
plugins {
id("com.custom.gradle.plugin.myplugin") version "1.1.0"
}
然后手动解析插件settings.gradle
:
pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.custom.gradle.plugin.myplugin") {
useModule("com.custom:com.custom.gradle.plugin.myplugin:${requested.version}")
}
}
}
}
有关更多详细信息,请参阅插件解析规则 。
推荐阅读
- java - 如何在java中创建一个带有节点的通用类型的get方法
- reactjs - 在 React 中仅渲染下一个未填充的表单组件
- python - 在Python中计算日期之间的天数?
- datetime - 如何将 chrono DateTime 设置为特定的日期和时间?
- java - 为 Jackson 自定义反序列化程序抛出带有 HTTP 状态代码的自定义异常
- python - 微信评论页面有链接,但是抓包软件和get请求获取的内容不一样
- arrays - 合并来自多个工作表的表
- arrays - 从 Bash 中的标准输入文件动态填充两个数组
- android - 画布不在 SurfaceView 中绘制
- maven - 存储库测试单独运行但整体失败(mvn 测试)