6

We have a multiproject with a settings.gradle and no build.gradle in the root project.

The default behaviour of gradle is just look up the settings.gradle file on the top dir and read the build.gradle for every project defined before.

My problem is: depending on the environment where the multiproject has been checked out, I want to run as default "build2.gradle" instead of "build.gradle" when running a build from the root project.

What is the best way to do it??

Thanks

Ken
  • 1,691
  • 5
  • 22
  • 38
lqbweb
  • 1,684
  • 3
  • 19
  • 33

2 Answers2

3

ok, done...

In settings.gradle:

String myFileName = "build2.gradle"

rootProject.buildFileName = myFileName
rootProject.children.each { project ->
    project.buildFileName = myFileName
    assert project.projectDir.isDirectory()
    assert project.buildFile.isFile()
}
Jean Bob
  • 565
  • 10
  • 24
lqbweb
  • 1,684
  • 3
  • 19
  • 33
3

Or for nested multiproject in settings.gradle:

setBuildFileName(rootProject)

def setBuildFileName(project) {
    project.children.each { childProject ->
    childProject.buildFileName = "${childProject.name}.gradle"
    assert childProject.projectDir.isDirectory()
    assert childProject.buildFile.isFile()
    setBuildFileName(childProject)
  }
}
Cedric Thiebault
  • 1,015
  • 1
  • 15
  • 28
  • I think this is useful. Reading the user guide, I thought that this would be coming out-of-the-box from gradle, but it didn't. Please correct me if I am mistaken. https://docs.gradle.org/current/userguide/intro_multi_project_builds.html 8.1 – Kilokahn Apr 11 '16 at 20:25