Search code examples
gradlebuild.gradlegradlew

In gradle is it possible to include a different jar based on a flag


If I have a simple gradle java build, can I somehow swap out one of the jar dependencies, say jarX for jarY based on a flag?

e.g.:

if running ./gradlew build - then include jarX

but if running ./gradlew build -specialBuild - then include jarY instead of jarX


Solution

  • Yes, you can use conditional statements on the dependencies {} closure.

    dependencies {
        if (project.hasProperty("useX")) {
            implementation 'x:x:x'
        } else {
            implementation 'y:y:y'
        }
    }
    

    call as

    gradle -PuseX=true