javagradleplugins

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


I have built a Gradle plugin and published it to the local maven repository. I can see it in my ~/.m2/repository. However, when I run a Gradle project to use this plugin, it does not even look in the local repository...at least, not based on the output.

It reports this when running from the command-line:

FAILURE: Build failed with an exception.

Where: Build file 'D:\Work\MuseProject\update4j-gradle-plugin\example\build.gradle' line: 15

What went wrong: Plugin [id: 'net.christophermerrill.gradle.update4j', version: '0.1'] 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 'net.christophermerrill.gradle.update4j:net.christophermerrill.gradle.update4j.gradle.plugin:0.1')

Searched in the following repositories: Gradle Central Plugin Repository

I have added mavenLocal() to the buildscript configuration. I also tried adding the specific dependency (as was suggested elsewhere) with no effect

buildscript {
  repositories {
      mavenLocal()
  }
  dependencies {
      classpath 'net.christophermerrill:update4j-gradle-plugin:0.1'
  }
}

Best I can tell from the output, it is not even looking in the local repository, but I am not 100% sure. Using the --scan and --info options does not provide any additional insights - they appear to do nothing at all, which I suspect is because the failure appears before the plugins finish loading (just guessing).

Is there a way to determine if Gradle is looking in the local Maven repo? I am trying to eliminate this as a possibility. The alternative, of course, is that my plugin is not published correctly. That will be my next question, after I settle this one :)


Solution

  • I think that specifying a custom plugin repository looks promising: this feature lets you configure the plugins{} DSL to resolve from other repositories in addition to the gradle plugin portal. I think you'd want to update your settings.gradle with configuration something along the lines of:

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

    (Note that this code block needs to appear at the top of settings.gradle).