Hi, Just been hit by some strange gradle behavior. My android (though I believe my question is generic to gradle tool) gradle build file contains dependency to a jar file as pasted below:
compile files(‘lib/some-library.jar’) }
After a few hours of fight everything works fine but initially I had a typo in path to that jar file. I’d expected that such typos should cause build process to fail so one can easily detect/find the problem. Instead gradle ignores the fact that given path is wrong. Even running gradle with ‘-debug’ option didn’t help finding the problem - I could find a line in gradle that passed mistyped path of file to some command and this command succeeded.
Is there a way to force gradle to be pedantic and check correctness of all paths? Shouldn’t such pedantic behavior be default? It is so obvious that I simply expected it to work this way.
thanks in advance Marcin
There’s no way to really do this.
The ‘files()’ construct can be used to model files that are yet to exist (i.e. will be built later) so this can’t be eagerly evaluated.
If you want stricter behaviour, I suggest not using file dependencies but repository dependencies instead.
Thanks for clarification but my question was a little different: I don’t need eager evaluation. I just need normal evaluation.
No matter whether such library exists before build starts or is created during build, it should be verified that it actually exists when it is passed by gradle to “javac” command during java source file compilation.
If my java source code depends on many jar files and path of one of them is mistyped then I get compile error saying that some class Foo could not be found. Now I need to guess in which jar-file this class is present to find mistyped path. I think that build tool should be smart enough to tell me which path I mistyped. It is easy to implement and I don’t really understand why it works the other way - gradle silently ignores missing jar-file and passes its path to javac command.
Maybe It is how gradle works and I just don’t understand its philosophy but frankly I cannot see any use case in which such behavior (silently ignoring missing jar-files) might be useful.
I’m not disagreeing that Gradle should assert that the classpath argument passed to javac refers to existing files. The current behaviour is not by design, but by omission.
It’s not been raised before because most people use repository based dependencies instead of anonymous file dependencies and there are “validated”.