Gradle plugin with custom group id
Asked Answered
P

1

6

Gradle 6.1

I am having difficulties to use the new plugin configuration mode in Gradle with a custom plugin coming from a custom repository.

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"
}

I get this error:

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 will use the plugin id as its group id.

It works if I use the old ways:

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")

Is there a way to specify the group id with the 'id' command? Or am I breaking the plugin definition's contract with that old plugin?

Predetermine answered 3/2, 2020 at 0:1 Comment(1)
Maybe related: stackoverflow.com/questions/37285413Pantagruel
C
4

In order to use the newer/preferred plugins { } DSL, the custom plugin must publish a plugin marker artifact.

If the custom plugin is able to be modified, then I suggest updating to make use of the Java Gradle Plugin Development plugin which will create the marker for you.

If the plugin is not able to be updated, then you can still use the plugins { } block, but you'll need to manually resolve the plugin:

In the main build.gradle:

plugins {
    id("com.custom.gradle.plugin.myplugin") version "1.1.0"
}

Then resolve the plugin manually in settings.gradle:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.custom.gradle.plugin.myplugin") {
                useModule("com.custom:com.custom.gradle.plugin.myplugin:${requested.version}")
            }
        }
    }
}

See Plugin Resolution Rules for more details.

Compelling answered 3/2, 2020 at 0:47 Comment(1)
Thanks for the swift response. I guess that, if we want to continue using it, we need to change this indeed.Predetermine

© 2022 - 2024 — McMap. All rights reserved.