gradlex-org / build-parameters

Compile-safe access to parameters supplied to a Gradle build
https://gradlex.org/build-parameters
Apache License 2.0
101 stars 5 forks source link

Allow for renaming of values #135

Open inktomi opened 1 year ago

inktomi commented 1 year ago

When working with builds, sometimes we cannot control the names that variables have. For instance, when running a build from Android Studio a flag is passed called "android.injected.invoked.from.ide".

It would be great to be able to read that into builds in a better way than miss-using groups:

    group("android"){
        group("injected"){
            group("invoked") {
                group("from") {
                    bool("ide") {
                        description.set("Whether or not the current build was started from within Android Studio")
                        defaultValue.set(false)
                    }
                }
            }
        }
    }

Would it be possible to simplify this in any way? Could build-parameters allow for renaming properties perhaps? For example, it would be nicer if we could define this like:

    bool("invokedFromIde"){ 
        source = "android.injected.invoked.from.ide"
        //...
    }
jjohannes commented 1 year ago

Thank you for sharing this use case. @britter and I will discuss this and get back to this.

britter commented 1 year ago

@inktomi this doesn't look like a parameter a build user would pass. It looks like one that is automatically passed by some tooling. Why are you modelling it as a build parameter? Is it to get around the parameter validation that will fail the build in case an unknown parameter is passed?

inktomi commented 1 year ago

The use case we have is that we want to know when a build is running inside a developer's IDE. In that case, we can skip gradle plugins and other logic that's not needed for developer builds. Android Studio (and other IDEs I'm sure) inject properties like android.injected.invoked.from.ide when they're executing a build.

britter commented 1 year ago

So, this is about a parameter that the IDE injects. It's not something that a developer would pass via the command line. Again, why are you modeling this as a build parameter? This plugin is really about parameters meant to be passed by developers to they build from the command line.

Do you want the compile-safe accessor to write some conditional local reacting to it?