Gradle Pass Configuration on Command Line

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

It is sometimes necessary to pass environment-specific configuration to the build . An example is the URL of a container registry, which may different values relative to the environment the build is executed. The best place for such configuration is not in build.gradle, as we want to avoid editing it for each environment the build is supposed to execute in. One option, which works well for build containers, is to use custom environment variables. Another option is to use command line-specified system properties, as shown below.

Let's assume we use com.palantir.docker, but we don't want to hardcode the registry URL and the image tag in build.gradle. We want to read it from the build environment instead. One way to do it is to use something like this:

gradle -Decr.registry.url=... -Decr.image.tag= docker dockerPush

If not provided on command line, those configuration elements can always fall back to build.gradle hardcoded values.