Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve a plugin using the new plugin mechanism in Gradle

While trying to upgrade some of our scripts to Gradle 4.0.1 on of the plugins we are using is failing and I thought of fixing that plugin first. The plugin is a third party open source project.

So I have cloned the project and tried to compile it. However it fails with following message:

c:\source\gradle-xld-plugin>gradlew build

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\source\gradle-xld-plugin\build.gradle' line: 2

* What went wrong:
Plugin [id: 'com.gradle.plugin-publish', version: '0.9.7'] was not found in 
any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- maven(https://artifactory/java-v) (Could not resolve plugin artifact 'com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:0.9.7')

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output.

BUILD FAILED in 0s

The build.gradle script for the plugin starts like this:

plugins {
  id "com.gradle.plugin-publish" version "0.9.7"
  id "com.github.hierynomus.license" version "0.11.0"
  id 'nebula.nebula-release' version '4.0.1'
  id "com.jfrog.bintray" version "1.7.3"
}

In addition to this the company policy dictates we have to go through an internal artifactory server, so following has been added to the settings.gradle file:

pluginManagement {
    repositories {
        maven {
            url "https://artifactory/java-v"
        }
    }
}

The jar file exists at following location: https://artifactory/java-v/com/gradle/publish/plugin-publish-plugin/0.9.7/plugin-publish-plugin-0.9.7.jar

but when I look at the error message I am a little puzzled that it says that it cannot find com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:0.9.7. It seems to have suffixed the id with .gradle.plugin.

Does anyone know whether I am looking at the wrong location or how come it is suffixing the id with .gradle.plugin. And shouldn't it look at a location that has the GAV like this: com.gradle.plugin-publish:com.gradle.plugin-publish:0.9.7?

And does anyone know about how the resolution mechanism for the new plugin mechanism in Gradle works.

Thanks in advance

Edit Thanks to Mateusz Chrzaszcz I was able to progress.

The only caveat I have with the solution is that it seems like a workaround rather than a solution. But it works!

In addition to his solution you had to resolve the plugins. I was able to hack my way to actually resolve the appropriate names.

In order to do so one has to do as follows:

  1. In a webbrowser go for the plugin: id "com.github.hierynomus.license" version "0.11.0" go to following URL: https://plugins.gradle.org/api/gradle/4.0.1/plugin/use/com.github.hierynomus.license/0.11.0
  2. The json returned contains the GAV needed in the useModule call. Use that

The following serves as an example:

resolutionStrategy {
    eachPlugin {
        if (requested.id.namespace == 'com.gradle' && requested.id.name == 'plugin-publish') {
            useModule('com.gradle.publish:plugin-publish-plugin:0.9.7')
        } else if(requested.id.namespace == 'com.github.hierynomus' && requested.id.name == 'license') {
            useModule('nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0')
        }
    }
}
like image 389
M. A. Tanaka Avatar asked Jul 21 '17 23:07

M. A. Tanaka


People also ask

How do I add plugins to build Gradle?

Publishing the Plugin in a Local Directory Build and run and you'll see the plugin directory in your desired location. Now run ./gradlew clean to clean Gradle, and then run ./gradlew -q writeModuleDependencies and enjoy your plugin!

Which are the two types of plugins in Gradle?

There are two general types of plugins in Gradle, binary plugins and script plugins.

What is Buildscript in build Gradle?

The buildscript is for the build.gradle file itself. So, this would contain dependencies for say creating RPMs, Dockerfile , and any other dependencies for running the tasks in all the dependent build.gradle.


1 Answers

Try to implement Plugin Resolution Rules.

According to gradle documentation:

Plugin resolution rules allow you to modify plugin requests made in plugins {} blocks, e.g. changing the requested version or explicitly specifying the implementation artifact coordinates. To add resolution rules, use the resolutionStrategy {} inside the pluginManagement {} block

like that:

pluginManagement {
 resolutionStrategy {
  eachPlugin {
      if (requested.id.namespace == 'com.gradle.plugin-publish') {
          useModule('com.gradle.plugin-publish:0.9.7') //try a few combinations
      }
  }
}
repositories {
  maven {
    url 'https://artifactory/java-v'
  }
 }
}

Keep in mind this is incubating feature though.

like image 88
Mateusz Chrzaszcz Avatar answered Nov 15 '22 08:11

Mateusz Chrzaszcz