unexplored
unexplored

Reputation: 1424

How to use different settings.gradle files for different environments

The problem

I have two projects, A (ui) and B (background service). Project A has a dependency on B. Project B gets published to a maven repository and included in project A like so in build.gradle

debugImplementation ('com.example:project-B:0.0.0-SNAPSHOT') { changing = true }
releaseImplementation ('com.example:project-B:1.6.2')

This works, but it's a pain to validate my service changes on the UI side. I need to publish project B to my nexus repo and resync project A.

I changed project A to the following:

build.gradle:

debugImplementation project(":project-b")

settings.gradle:

include ':project-a'
include 'project-b'
project(':project-b').projectDir = new File(settingsDir, "${project-b-path}")

I can have all my code in one IDE window and have A use local instance of B. But the problem is this will break on my build server since there is no local B project, only the one on nexus.

Is there a way to configure the settings.gradle for release vs debug? I can just commit my changes and overwrite the file on the build server, but I want to know if there are other ways?

Upvotes: 1

Views: 2061

Answers (1)

user3038039
user3038039

Reputation: 66

You can use gradle command line to set which settings or build file should be used.

Settings File

-c, --settings-file
Specifies the settings file. For example: gradle --settings-file=somewhere/else/settings.gradle

Build File

-b, --build-file
Specifies the build file. For example: gradle --build-file=foo.gradle. The default is build.gradle, then build.gradle.kts, then myProjectName.gradle.

You can find more details here: Gradle docs: Environment options

Upvotes: 3

Related Questions