Use a custom plugin stored in Nexus


(Paul Broughton) #1

Hi, apologies if this is a silly question but I seem unable to find a clear answer.

I have written a custom plugin which has been successfully uploaded as a release into my local nexus repo.
From a maven perspective it all seems to be fine. The pom looks like this

project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.spidasolutions.gradle</groupId><artifactId>SpidaGradleBasePlugin</artifactId><version>0.1.0</version><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies></project>

in my settings.gradle I have specified the repo set
pluginRepositories {
maven {
url ‘https://mynexus/nexus/repository/maven-releases
}
}

in my build.gradle I am referencing the plugin
plugins {
id “com.spidasolutions.gradle.SpidaGradleBasePlugin” version “0.1.0”
}

the build however fails saying the plugin doesnt exist. I assume I need to customise the way the artefact goes into nexus but I cant seem to find anything to help me with this

* What went wrong:
09:05:17.220 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Plugin [id: 'com.spidasolutions.gradle.SpidaGradleBase', version: '0.1.0'] was not found in any of the following sources:
09:05:17.220 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
09:05:17.220 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
09:05:17.220 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - maven(https://mynexus/nexus/repository/maven-releases) (Could not resolve plugin artifact 'com.spidasolutions.gradle.SpidaGradleBase:com.spidasolutions.gradle.SpidaGradleBase.gradle.plugin:0.1.0')

any assistance would be much appreciated.
thanks
Paul


(James Justinic) #2

In order to use the new plugins DSL, it is necessary to publish both the plugin implementation artifact and a marker artifact. The marker artifact is used to resolve the implementation artifact from the id that you provide in the plugins {...} block. The exception suggests that you did not publish the marker artifact (this can be handled automatically for you).

Does your build that published the plugin look like the example plugin example in the user guide? Your usage of the plugin looks fine.


(Paul Broughton) #3

HI James, thanks for the advice. That was what was missing for sure.
I have applied changes that should I would have said have worked but I am still not resolving the plugin for some reason.

I have the gradlePlugin section now
gradlePlugin {
plugins {
spidagradlebase {
id = "com.spidasolutions.gradle.spidagradlebase"
implementationClass = “com.spidasolutions.gradle.SpidaGradleBase”
}
}
}
my plugin has a properties file in the META-INF/gradle-plugins folder to match the id.
I can run gralde plublish successfully and the marker is being generated. It looks like it should be fine to me, the generated POM is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.spidasolutions.gradle.spidagradlebase</groupId>
  <artifactId>com.spidasolutions.gradle.spidagradlebase.gradle.plugin</artifactId>
  <version>0.1.0</version>
  <packaging>pom</packaging>
  <dependencies>
    <dependency>
      <groupId>com.spidasolutions.gradle</groupId>
      <artifactId>SpidaGradleBasePlugin</artifactId>
      <version>0.1.0</version>
    </dependency>
  </dependencies>
</project>

I am then referencing the plugin
plugins {
id ‘com.spidasolutions.gradle.spidagradlebase’ version '0.1.0’
id 'maven’
id ‘groovy’
}

the error appears much the same
* What went wrong:
16:33:12.023 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Plugin [id: ‘com.spidasolutions.gradle.spidagradlebase’, version: ‘0.1.0’] was not found in any of the following sources:
16:33:12.023 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
16:33:12.023 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - Gradle Core Plugins (plugin is not in ‘org.gradle’ namespace)
16:33:12.023 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - maven(https://mynexus/nexus/repository/maven-releases/) (Could not resolve plugin artifact ‘com.spidasolutions.gradle.spidagradlebase:com.spidasolutions.gradle.spidagradlebase.gradle.plugin:0.1.0’)
16:33:12.023 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - Gradle Central Plugin Repository (no ‘com.spidasolutions.gradle.spidagradlebase’ plugin available - see https://plugins.gradle.org for available plugins)

I thought it might be usefull to know that I can resolve the marker artifact using maven

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
    -DrepoUrl=https://mynexus/nexus/repository/maven-releases/ \
   -Dartifact=com.spidasolutions.gradle.spidagradlebase:com.spidasolutions.gradle.spidagradlebase.gradle.plugin:0.1.0:pom

(Paul Broughton) #4

Not sure if this helps the discussion but looking into the --debug output I can see gradle is contructing the url for the marker pom correctly. I can take that url and use curl to get the file

07:22:17.398 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.DefaultExternalResourceArtifactResolver] Loading https://mynexus/nexus/repository/maven-releases/com/spidasolutions/gradle/spidagradlebase/com.spidasolutions.gradle.spidagradlebase.gradle.plugin/0.1.0/com.spidasolutions.gradle.spidagradlebase.gradle.plugin-0.1.0.pom
07:22:17.398 [DEBUG] [org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor] Constructing external resource: https://mynexus/nexus/repository/maven-releases/com/spidasolutions/gradle/spidagradlebase/com.spidasolutions.gradle.spidagradlebase.gradle.plugin/0.1.0/com.spidasolutions.gradle.spidagradlebase.gradle.plugin-0.1.0.pom

is it possible this is a bug in the plugin process for gradle?

thanks
Paul


(James Justinic) #5

Do you have a valid certificate for your Nexus server?

I can reproduce your latest result, but only if I install a self-signed certificate for HTTPS on Nexus.


(Paul Broughton) #6

yup, I certainly do. I am able to use the old method to resolve the plugin
from nexus just fine (I thought I would give that a go yesterday).


(Ivan Šarić) #7

Hi Paul,

It seems I’m having the same problem you had.
Were you ever able to use the plugins DSL successfully with your custom plugins on Nexus or are you still using the buildscript block?
It looks like the issue is that the plugins dsl ignores the transitive dependency in the marker pom.
I tested this on Gradle version 4.10.

Best wishes,
Ivan