6

I am new to gradle (leaving from maven). Now I have a problem. I have a gradle build where I want to use the com.bmuschko.nexus plugin. But my project depends on another project where I also want to use the com.bmuschko.nexus plugin.

So when I build I get an Exception:

Plugin 'com.bmuschko.nexus' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add  "apply plugin: 'com.bmuschko.nexus'" to the body of the script to use the plugin.

But when I do so -> Add apply plugin: 'com.bmuschko.nexus' to the body of the script to use the plugin I get another exception:

> Failed to apply plugin [id 'com.bmuschko.nexus']
   > Plugin with id 'com.bmuschko.nexus' not found.

How can I solve this?

settings.gradle

include ':config'
project(':config').projectDir = new File(settingsDir, '../zConfig')

build.gradle

plugins {
        // id "com.bmuschko.nexus" version "2.3" // already in classpath
        id "me.champeau.gradle.antlr4" version "0.1"
}

apply plugin: 'java'
apply plugin: 'maven'
//apply plugin: 'com.bmuschko.nexus'

dependencies {
        compile project(':config')
}

EDIT: to reproduce just clone the repo https://github.com/KIC/stackoverflow/tree/master/gradleproblem and try gradle tasks in the bar directory

EDIT2: Seems that I could solve the nexus upload problem by omitting the plugin and follow this answer https://stackoverflow.com/a/16766946/1298461

But since I have also an antlr project and a second antlr project extending the grammar of the first, I have the very same problem just with another plugin. I think I could solve this when I use a parent build.gradle and subprojects{}. But this is exactly the reason why I leave maven and move to gradle. My sub-modules can and should also live independently with different versions.

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
KIC
  • 5,887
  • 7
  • 58
  • 98
  • It seems that if the plugin is already applied you can just use it. No need for reapplying it but just pass configuration and run appropriate task. Are tasks from mentioned plugin outlined when `gradle tasks` run? – Opal Feb 26 '15 at 12:01
  • 1
    Sadly no, since the project is in dependecies the setup will not work an thus gradle fails `Could not find method nexus() for arguments` – KIC Feb 26 '15 at 12:05
  • Is that project hosted online? – Opal Feb 26 '15 at 12:12
  • @Opal no its not online – KIC Feb 26 '15 at 12:32

1 Answers1

1

'com.bmuschko.nexus' plugin is already on config project. That's the reason of the following error: Plugin 'com.bmuschko.nexus' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add "apply plugin: 'com.bmuschko.nexus'" to the body of the script to use the plugin.

I did the following:

Edit build.gradle (config project)

apply plugin: 'java'
apply plugin: 'maven'
apply from: '../repos.gradle'

Edit build.gradle (bar project)

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.bmuschko:gradle-nexus-plugin:2.3'
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.bmuschko.nexus'
apply from: '../repos.gradle'

dependencies {
        compile project(':config')
}

Then I run gradle tasks and everything is ok.

Eddú Meléndez
  • 6,107
  • 1
  • 26
  • 35