I try to use class from “commons-io-1.4.jar” library in my custom task. If I don’t define any dependencies, I get successfull compile and “ClassNotFoundException” error on execution. If I copy “commons-io-1.4.jar” into “lib” project folder and define it as dependency, then all works fine. But if I set dependency on library file from standard Gradle instalation, then I get the same error “ClassNotFoundException”. Look at details below.
If you can’t give access to library classes in my code, then you need to raise error, when I try to use this library in dependencies.
You should never set an explicit dependency on a Jar in the Gradle distribution. Gradle plugins should declare a ‘compile gradleApi()’ dependency. For ‘buildSrc’, this dependency is declared automatically.
You contradict to yourself. If “commons-io-1.4.jar” library is part of “Gradle API”, then it must be available to my code without any error. If it’s not part, then why I can’t make dependency on already existing file? Why I must make copy of this library and make dependency on this copy? It have so sense.
I think, the root of this problem lie in Gradle classloader, which put “commons-io-1.4.jar” library in some classloader’s tree node, where it is not available for my plugin code.
Looking at this again, the problem may be related to your use of an internal Gradle class (‘org.gradle.api.internal.file.FileResolver’). Please try without using that (or any other) internal class, and see if it solves the problem.