Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 20723

Call task of another build.gradle file using a groovy method

$
0
0

I have three Gradle projects residing in this kind of folder structure (I have flattened the structure, because i am not sure how to format it with ASCII-Code in this editor):

/intellij-projects/big-project/small-project-AAA/build.gradle
/intellij-projects/big-project/small-project-BBB/build.gradle
/intellij-projects/big-project/small-project-CCC/build.gradle

From within the build.gradle file of the small-project-BBB I want to execute the jar task of the small-project-AAA and small-project-CCC using a groovy method definition in the following fashion:

def triggerTasksInSpecificBuildFile(relativeBuildFilePath, tasksToTrigger) {
    println "Trying to trigger"
    return tasks.create("Trigger", GradleBuild) {
        buildFile = relativeBuildFilePath
        tasks = tasksToTrigger
    }
}

task buildOtherSmallProjects {
    doLast {
        triggerTasksInSpecificBuildFile("../small-project-AAA/build.gradle", ['jar'])
        triggerTasksInSpecificBuildFile("../small-project-CCC/build.gradle", ['jar'])
    }
}

Problem is, when I execute in my bash:

my-user@my-laptop:/intellij-projects/big-project# ./gradlew -b small-project-BBB/build.gradle buildOtherSmallProjects

It only prints “Trying to trigger”, but no jar files are created inside the folders small-project-AAA/build and small-project-CCC/build as they would if I had executed the corresponding jar tasks like this:

my-user@my-laptop:/intellij-projects/big-project# ./gradlew -b small-project-AAA/build.gradle jar
my-user@my-laptop:/intellij-projects/big-project# ./gradlew -b small-project-CCC/build.gradle jar

Just in case: I know that there is the possibility of using a settings.gradle file, but in real life -like actually- the project is much more complex and nested and I cant just introduce such a file, because it would break things elsewhere.

Can someone explain me what I am getting wrong here?


Viewing all articles
Browse latest Browse all 20723

Trending Articles