Gradle for multiple projects, change the default assembly name (build.gradle)

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

The default behavior of gradle is simply to look at the settings.gradle file in the top directory and read build.gradle for each project defined earlier.

My problem: depending on the environment in which the multiproject was extracted, I want to run "build2.gradle" by default instead of "build.gradle" when starting the build from the root project.

What is the best way to do this?

thanks

+5
source share
2 answers

OK done ...

In .gradle settings:

String myFileName="build2.gradle" rootProject.buildFileName = "${myFileName}" rootProject.children.each {project -> project.buildFileName = "${myFileName}" assert project.projectDir.isDirectory() assert project.buildFile.isFile() } 
+2
source

Or for a 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) } } 
+3
source

Source: https://habr.com/ru/post/1432053/


All Articles