How to apply a plugin not in Gradle Core or Gradle Central Plugin Repository


(Steve Cohen) #1

I’m confused. I thought I’d been doing this for some time, but this introduces a new wrinkle.

I’ve developed a package of plugins based on the nebula rpm plugin version 3.4.0 . I’ve successfully created several buildscripts that apply my plugins, which exist only in my maven local repository.

Now, however, I require a new feature in that plugin. I forked the os.nebula plugin and added my feature, and call my version 3.4.1, deploying it to my maven local repository, as I did my package of plugins. I now want to make my plugins apply my version of nebula-rpm and not 3.4.0.

The build script for my plugin package, which depends on nebula.rpm, is now failing saying that it could not find my plugin in the gradle core plugins or the gradle central plugin repo.

I’ve tried all the following strategies and none works.
1- no buildscript element

plugins {
  id 'jacoco'
  id 'com.gradle.plugin-publish' version '0.9.3'
  id "nebula.rpm" version "3.4.1"
  id "groovy"
  id "maven-publish"
}

2- Add build script with repositories

buildscript {
    repositories {
        mavenCentral name: "nexus", artifactUrls: ["http://corporate.maven.central/nexus/content/groups/corporate-public-group"]
        mavenLocal()
    }
}

plugins {
  id 'jacoco'
  id 'com.gradle.plugin-publish' version '0.9.3'
  id "nebula.rpm" version "3.4.1"
  id "groovy"
  id "maven-publish"
}

3- Add build script with repositories and dependencies

buildscript {
    repositories {
            mavenCentral name: "nexus", artifactUrls: ["http://corporate.maven.central/nexus/content/groups/corporate-public-group"]
        mavenLocal()
    }
    
    dependencies {
        classpath group: 'com.netflix', name: 'nebula.rpm',
                  version: '3.4.1'
    }
}

plugins {
  id 'jacoco'
  id 'com.gradle.plugin-publish' version '0.9.3'
  id "nebula.rpm" version "3.4.1"
  id "groovy"
  id "maven-publish"
}

(Marcin Zajączkowski) #2

The last one looks sensible. Just try to remove the id "nebula.rpm" version "3.4.1" line and add the following one at the bottom (outside the plugins block):

apply plugin: "nebula.rpm"

(Marcin Zajączkowski) #3

Btw, there is also something wrong with your repositories. Maybe it is just formatting issue or I don’t know some new syntaxt, but it should be rather:

buildscript {
    repositories {
        mavenCentral()
        maven { url: "http://corporate.maven.central/nexus/content/groups/corporate-public-group" }
        mavenLocal()
    }

    (...)
}

(Steve Cohen) #4

Really? It works, and the corporate one is a mirror of Maven Central, i.e. you’re supposed to use it instead of the real Maven Central.


(Marcin Zajączkowski) #5

Quoting myself:

I have never used it.


(Steve Cohen) #6

ok. Your original suggestion works, by the way, thanks.


(Schalk Cronjé) #7

There are couple of things going on here:

  • The plugins {} block will only look in plugins.gradle.org for plugins. I fyou need additional dependencies you need to have a buildscript [] block.
  • Once you start going down the buildscript route for plugins, you need to apply those with the apply plugin syntax.
  • The order of looking looking for dependencies is dependent on the order in which repositories are listed. If you want your local repo to be hit before mavenCentral you need to place it higher up in the list.

HTH