【问题标题】:Gradle plugin with custom group id具有自定义组 ID 的 Gradle 插件
【发布时间】:2020-02-03 00:01:15
【问题描述】:

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?还是我违反了插件定义与旧插件的约定?

【问题讨论】:

标签: gradle gradle-plugin


【解决方案1】:

为了使用更新/首选的plugins { } DSL,自定义插件必须发布plugin marker artifact

如果自定义插件可以修改,那么我建议更新以使用 Java Gradle Plugin Development plugin,它将为您创建标记。

如果插件无法更新,您仍然可以使用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}")
            }
        }
    }
}

更多详情请见Plugin Resolution Rules

【讨论】:

  • 感谢您的快速回复。我想,如果我们想继续使用它,我们确实需要改变它。
猜你喜欢
  • 2012-09-16
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多