Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish custom plugin to Maven local and then use it in another local project? [duplicate]

I have built a Gradle plugin that worked great under buildSrc of another Gradle project. Now I have moved it to its own project and want to publish it to my local Maven repo so that I can use in the original project (without it in buildSrc). The longer-term goal will be to publish it for others, of course.

The problem is that after publishing it, the other project cannot find it. I can see the files in ~/.m2/repository and they seem correct (best as I can tell). I have tried a dozen variations of plugin id, group id and project name combinations in both projects and they all result in a failure to load the plugin in the other project:

Plugin [id: 'update4j-gradle-plugin', version: '0.1'] was not found in any of the following sources:

Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/4.9/userguide/standard_plugins.html for available core plugins)

Plugin Repositories (could not resolve plugin artifact 'update4j-gradle-plugin:update4j-gradle-plugin.gradle.plugin:0.1')

Searched in the following repositories:

Gradle Central Plugin Repository

When I go look in my local Maven repo, I find the Plugin Marker Artifacts, and they appear correct, but I don't really know.

The plugin setup and publishing config in Gradle is:

group 'net.christophermerrill'
version '0.1'
gradlePlugin {
    plugins {
        update4j {
            id = 'update4j-gradle'
            implementationClass = 'net.christophermerrill.update4j.gradle.Update4jPlugin'
        }
    }
}

publishing {
    repositories {
        mavenLocal()
    }
}

The plugin is referenced from the other project like this:

id 'update4j-gradle' version '0.1'

The entire project is on GitHub: https://github.com/ChrisLMerrill/update4j-gradle-plugin so you can check it out and try it. Build the main project and publish it from the root folder with:

gradlew publishToMavenLocal

And the in the example folder, run any gradlew command to show the problem, e.g.

gradlew run
like image 353
CMerrill Avatar asked Aug 09 '18 19:08

CMerrill


1 Answers

The answer is that everything I had was correct, but a pluginManagement block is needed in settings.gradle in order to read plugins from non-standard repositories. It is the accepted answer on this question:

Why does Gradle not look in the local maven repository for plugins?

like image 141
CMerrill Avatar answered Nov 15 '22 02:11

CMerrill