Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 426
CMerrill Avatar asked Aug 09 '18 17:08

CMerrill


People also ask

Does Gradle use Maven local repository?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.

Can Maven plugins be used in Gradle?

You can't use a Maven plugin as-is in Gradle; you'll have to port it to a Gradle plugin. How difficult this is depends on how many Maven APIs the plugin is using. Another strategy might be to call into Maven via Gradle's Exec task.

How do I convert Maven plugins to Gradle?

To convert Maven to Gradle, the only step is to run gradle init in the directory containing the POM. This will convert the Maven build to a Gradle build, generating a settings. gradle file and one or more build. gradle files.

Where is the Gradle local repository?

Gradle's local repository folder is: $USER_HOME/. gradle/caches/modules-2/files-2.1.


1 Answers

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

like image 93
bto Avatar answered Sep 28 '22 03:09

bto