Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: Inject plugins to subprojects

Tags:

gradle

I came across gradle plugin to help me to deal with dotted property names. It works fine in single project when used like this:

apply plugin: 'config'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.esyfur:gradle-config-plugin:0.4.+'
    }
}

task printProps() {
    println(config.grafana.url)
}

However, I want to use this plugin in multiple projects (multi-module) and would like idealy not to repeat such initialization in every project but rather inject it somehow to have it more manageable.

I have failed to find out how to do it or if it can be done. I tried e.g. in parent build.gradle use this:

allprojects {
    apply plugin: 'config'
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.esyfur:gradle-config-plugin:0.4.+'
    }
}

but it does not work. Gradle complains that it can not find property 'config' on task.

Update

After Peter's comment I started wondering around and creating an example project from the scratch and incrementally get it closer to my 'real project'. I was not completely precise in describing my setup. In settings.gradle I use

rootProject.children.each { project ->
    project.buildFileName = "${project.name}.gradle"
} 

which causes this problem. Everything works fine When switched back to build.gradle names.

like image 621
jojovilco Avatar asked Nov 23 '22 14:11

jojovilco


1 Answers

The problem is that your settings.gradle doesn't configure rootProject.buildFileName to match the non-standard filename used for the build script. Therefore the build script doesn't get evaluated, and its buildscript block never takes effect.

like image 91
Peter Niederwieser Avatar answered Nov 25 '22 04:11

Peter Niederwieser