-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give good error if an optional parameter is not set #25
Comments
As far as I can see, there is no way to implement this with Gradle Providers. My approach was to use However, the errors we see in the tests on the PR show that this approach will always throw the error if you use |
There is also this perspective to look at this: We do not only have two kinds of parameters, but three:
Right now, we support 1 and 2, but 3 is not explicitly supported. I think that 3 might actually be more common than 2. E.g. the example used in our docs – |
Team decision We realized that we can implement this by adding a |
Unfortunately after thinking about it some more, I realized what we discussed doesn't work. Let's say I have a build parameter that models the password to a maven repository for publishing: buildParameters {
string("repositoryPassword") {
mandatory.set(true)
}
} I want this to be present when it's needed, e.g. when the build publishes some artifacts on CI, but I don't want developers having to set this every time, because developers simply don't have the credentials to deploy to the production repository. Now when I configure the maven publication it will look like this: publications {
repositories {
maven {
password = buildParameters.repositoryPassword
}
}
} This code will fail at configuration time no matter whether a publication task was requested or not. First I thought this is a problem with publications {
repositories {
maven {
password.set(provider { buildParameters.repositoryPassword })
}
}
} So I would always have to wrap this value into a provider because otherwise the code of the generated getter would be executed at configuration time. I think we can solve this be creating a new |
Yes you are right. The second point is important. You may not want to access the parameter at configuration time to not get an error for build runs where you do not need that parameter. For me this means, that the type of a mandatory parameter (e.g. of type string) would still be Then, if you only need the value for a certain task, it would only be accessed during task execution, or when the inputs of a task are calculated if the parameter provider is (part of) a task input. Unfortunately, the repository password is a bad example then, because it's not sufficiently lazy in Gradle itself - although it should be! This is a problem in Gradle itself. I can open an issue for that (this looks related gradle/gradle#20925). I think there are workarounds to do this lazily. I will see if I can get it working and then we can document it as this is a quite common thing you may want to do. For the documentation of mandatory parameters we should look for a clean example though. |
An optional build parameter is of typ
Provider<>
and returns a 'standard' Gradle provider implementation. If Gradle calls.get()
on it when the value is set, you always get the following (very useless) error:In the case if the Build Parameters plugin, we have all the information which property is not set (property name and env variable name). So we should be able to construct providers that automatically give a better error.
Example
Would be nice to write a task like this and automatically get a good error if
CATALINA_HOME
is not set:Right now I have to add a custom error through
.orElse(provider { ...
which is a bit ugly and verbose.The text was updated successfully, but these errors were encountered: