Why won't Gradle find my locally published plugin?

Viewed 21

I have one project which contains and publishes a Gradle plugin:

plugins {
    `java-gradle-plugin`
    `kotlin-dsl`
    kotlin("jvm") version "1.5.31"
    `maven-publish`
}

project.group = "com.company.gradle"
project.version = "1.0.0"

repositories {
    mavenCentral()
    gradlePluginPortal()
}

gradlePlugin {
    plugins.create("pomPlugin") {
        id = "com.company.gradle.pom"
        implementationClass = "com.company.gradle.pom.PomPlugin"
    }
}

Building this and publishing (via ./gradlew publishToMavenLocal) succeeds without errors. After it completes, my local maven repo ~/.m2/reposiory contains:

./com/company/
./com/company/gradle
./com/company/gradle/pom
./com/company/gradle/pom/maven-metadata-local.xml
./com/company/gradle/pom/1.0.0
./com/company/gradle/pom/1.0.0/pom-1.0.0.jar
./com/company/gradle/pom/1.0.0/pom-1.0.0.module
./com/company/gradle/pom/1.0.0/pom-1.0.0.pom
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/maven-metadata-local.xml
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0/com.company.gradle.pom.gradle.plugin-1.0.0.pom

Then I have another project that tries to use the plugin:

buildscript {
    repositories {
        mavenLocal()
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    kotlin("jvm") version "1.6.10"
    id("com.company.gradle.pom") version "1.0.0"
}

repositories {
    google()
    mavenCentral()
    mavenLocal()
}

but Gradle cannot resolve the plugin:

* What went wrong:
Plugin [id: 'com.foxit.gradle.pom', version: '1.0.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.foxit.gradle.pom:com.foxit.gradle.pom.gradle.plugin:1.0.0')
  Searched in the following repositories:
    Gradle Central Plugin Repository
1 Answers

Add this at the top of your settings.gradle file in the project where you want to use your plugin.

pluginManagement {
    repositories {
        mavenLocal()
        gradlePluginPortal()
    }
}

The gradlePluginPortal() bit is for "real" gradle plugins which have been published.

The mavenLocal() bit is for your locally published plugins.

The repositories blocks you have in the build.gradle are for dependencies and not plugins.

Related