Command-line option for build-wide properties?

Is there a way to set a command-line option for the entire execution context?

That is, the @Option decoration has the ability to provide a custom command-line option for a task. The downside of this functionality is that is requires a specific task to be named (it does not work with just an unmentioned default task), and the scope of what’s been declared applies to just the specific task.

What I’d really like is for the ability to provide a command-line option that would allow me to set a property across multiple tasks, or even multiple projects. For example, the ability to control the build flavor (e.g., “debug” or “release”), which could impact the compilation of many things, not just a singular task.

I can control this as a project property (e.g, -Pflavor=DEBUG), but I really like the functionality provided by @Option, such as making it an enum, and the documentation and validation that is baked in when I use it.

I suppose I could potentially make it a task-specific @Option, and then do something like gradle.ext.flavor = flavor in the setter for the option, but that seems a little hack-ish. It also still doesn’t work without explicitly specifying the task first, and I’d really love it if a user could just run ./gradlew --flavor=release.


I think -P or -D is your only option at this point. Perhaps file a feature request?

@fredc What’s the right way to do that (i.e., request a feature)? Create an issue on GitHub?

I created a GitHub issue for increased awareness / tracking of this request.

This request closely matches this existing request in GitHub