具有自定义组ID的Gradle插件

问题描述 投票:3回答:1

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个回答
1
投票

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

如果可以修改自定义插件,那么我建议您进行更新以使用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}") } } } } 以获取更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.