Old plugin syntax not working in gradle 4.0


(BrainStone) #1

Hello everyone.

I’m currently build a little script that contains common stuff for the development of my team. Since I can’t use the plugin block outside the main build script, I decided to use the old plugin syntax.

This is my common.gradle script:

buildscript {
    repositories {
        maven {
            name "Gradle-Plugins"
            url "https://plugins.gradle.org/m2/"
        }
    }
 
    dependencies {
        classpath "io.franzbecker:gradle-lombok:1.8"
    }
}

if (!project.hasProperty("type")) {
    println "You have to specify a type!"
    
    throw new NoSuchElementException("No type is specified!")
}

apply plugin: "java"
apply plugin: "maven"
apply plugin: "maven-publish"
apply plugin: "signing"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "io.franzbecker.gradle-lombok"

And when I include it in another build script, I get this error:

PS C:\Users\xxx\Modding\Gradle-Common\Empty Projects> gradle

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\xxx\Modding\Gradle-Common\common.gradle' line: 26

* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'io.franzbecker.gradle-lombok' not found.

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

BUILD FAILED in 1s

I’m using gradle 4.0 btw. How can I solve this?


(Sterling Greene) #2

Your buildscript {} block needs to be in the root build.gradle and then it should work.


(BrainStone) #3

@sterling That’s exactly what I’m trying to avoid. And according to the doc it should work that way.


(BrainStone) #4

A little further research shows that this isn’t working for over 5 years…

Well, at least the plugin block is planned to work outside the build.gradle file sooner or later…


(James Justinic) #5

More accurately, you are running into https://github.com/gradle/gradle/issues/1262, which is also a long-standing issue. The one you mentioned could be considered the opposite of what you’re wanting. Your work-around would be using the plugin class instead of the plugin id.

apply plugin: "io.franzbecker.gradle-lombok"

in your common.gradle changes to

apply plugin: io.franzbecker.gradle.lombok.LombokPlugin

(BrainStone) #6

Thanks a lot! That works!