1

When I execute gradle with the following command:

./gradlew publishToMavenLocal -PsplainVersion=null

I got the following error:

...
> Could not resolve all files for configuration ':graph-commons:scalaCompilerPlugins'.
   > Could not resolve io.tryp:splain_2.13.6:null.

It appears that null is not parsed properly as a control token, instead it becomes a string. Is there a method to help Gradle to understand it as a real null value?

tribbloid
  • 4,026
  • 14
  • 64
  • 103

1 Answers1

2

Gradle will effectively treat anything as an argument of some kind. There is no null checking whatsoever.

So if you need to ensure a null argument is not given to your build script, then you need to validate the argument is not null where it is being used.

tasks.register("verifyNonNull") {
    onlyIf {
        property("splainVersion") != 'null'
    }
}

If you are curious of Gradle's logic, check out the source of CommandLineParser.

Cisco
  • 20,972
  • 5
  • 38
  • 60
  • Thanks a lot, I'm using kts variant so it's probably easier to switch to the non-monadic type (so it is either empty or a value, but cannot be null) – tribbloid Oct 23 '21 at 19:06