Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import a Gradle script from the root into subprojects

Tags:

gradle

build

I want to do an 'apply from: ./gradle/script/common.gradle' in my root build.gradle and have it be available to all of my subprojects.

I've tried putting the apply in the 'subprojects' but because the path is relative it won't always resolve, (the subprojects are not flat). I've also put it outside of the subprojects at the root but then the targets aren't resolved by the subprojects.

I haven't been able to find a way to get the working directory in a way the 'apply from:' likes, or how to get the root directory or directory that the original gradle script is being executed from.

like image 361
Patrick Auld Avatar asked Sep 06 '12 19:09

Patrick Auld


1 Answers

In your root build.gradle.:

allprojects { // or: subprojects { ... }
    apply from: "gradle/script/common.gradle"
}

Should you ever need an absolute path to such a script, you can always do "$rootProject.projectDir/gradle/script/common.gradle".

like image 162
Peter Niederwieser Avatar answered Dec 03 '22 15:12

Peter Niederwieser