Gradle Pass Configuration on Command Line: Difference between revisions
No edit summary |
|||
Line 7: | Line 7: | ||
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 build.gradle, as we would like to avoid editing it for each environment the build is supposed to execute in. One option, which works well for build containers, is to [[Passing Configuration to a Gradle Build via Custom Environment Variables|use custom environment variables]]. Another option is to use command line-specified system properties, as shown below. | 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 build.gradle, as we would like to avoid editing it for each environment the build is supposed to execute in. One option, which works well for build containers, is to [[Passing Configuration to a Gradle Build via Custom Environment Variables|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|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 | Let's assume we use [[Com.palantir.docker|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, in a way similar to: | ||
gradle -Decr.registry.url=... -Decr.image.tag= docker dockerPush | 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. | If not provided on command line, those configuration elements can always fall back to build.gradle hardcoded values. |
Revision as of 20:11, 20 March 2019
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 build.gradle, as we would like 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, in a way similar to:
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.