buildintellij-ideagradleprojectstructure

How can I use multiple build.gradle files?


My project structure is:

Enter image description here

I want the user additionally to configure the build using some of the build scripts from the specifications directory, but the main build script to be used to configure the project as well.

Using the -b option gives the ability to specify another build script different from the default one, but I want this default one to be executed as well. I don't want to use apply from: and to add all scripts because user have to decide what he wants.

Is there a way to tell Gradle to add an additional build script - command line with which to configure extra the Project?


Solution

  • If you need this this, you could do something like this:

    apply from: "config/specifications/${project.spec}.gradle"
    

    which would then allow users to do e.g.

    ./gradlew -P spec=example
    

    See Configuring the Build Environment for more details on setting project properties from the command line.