How to extend configuration script in multi-project build without modifying it?


I need to add custom gradle configuration for a set of independent Java projects without modifying their main build.gradle scripts. I’ve created the simplest multi-project hierarchy as a demo.

Main config: $ cat build.gradle subprojects {

apply plugin: ‘java’

println “[PROJECT] $project” }

Settings: $ cat settings.gradle include ‘p1’, ‘p2’

Subdirectories p1 and p2 are empty for now.

Then I prepared the custom config file which imports the main config and add some custom configuration: $ cat custom.gradle apply from: ‘build.gradle’

subprojects {

println “[EXT] $project extension will be applied here” }

Now I run tests: $ gradle test --build-file custom.gradle and get error:

FAILURE: Build failed with an exception.

  • What went wrong: Task ‘test’ not found in root project ‘sample’. …

I don’t understand why this happens.

Can anybody explain me what is wrong and what is the possible solution for this case? I will really appreciate any help.

Thanks in advance.