How to avoid dependency on buildSrc in Production environment and specify .jar file with compiled files on the buildscript classpath?

Hi,

I implemented some Production deployment logic with my own .groovy classes which I dropped under my gradle’s project buildSrc directory. I then rely on these classes in my build.gradle script, and therefore, specify “import…” statements for the classes I need in build.gradle

It works great if I keep the buildSrc directory. Gradle sees buildSrc, automatically compiles source files and puts compiled classes on the buildscript’s classpath.

However, I do not want compilation and tests to run in Production. Thus, I do not want to carry my buildSrc directory to Production environment but instead want to carry the .jar file with already compiled classes and have this .jar loaded into my buildscript’s classpath.

I already tried specifying this code in both settings.gradle and build.gradle file, but that does not do the trick.

buildscript {

dependencies {

classpath files (‘lib/myClasses.jar’)

} }

When I try to run task that I defined in my build.gradle file, Gradle still complains about unknown imports at the top of my build.gradle script (which references classes found in myClasses.jar).

Does anyone know of a good solution here?

Thank you!

The buildscript {} block should do the trick. I can only imagine that the path to the Jar is incorrect, the Jar is missing, or that it doesn’t contain the classes that you are trying to import.

Yes, it was a file permission problem. It finally worked. Thank you!