Patrick Auld
Patrick Auld

Reputation: 1427

Import a Gradle script from the root into subprojects

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.

Upvotes: 14

Views: 8180

Answers (2)

Aditya Bhuyan
Aditya Bhuyan

Reputation: 458

Appending "apply false " in each line had solved the issue for me.

Example

id 'org.springframework.boot' version '2.5.5'  apply false
id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false

Upvotes: 0

Peter Niederwieser
Peter Niederwieser

Reputation: 123986

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".

Upvotes: 30

Related Questions