buildSrc classpath


(William Zeitler) #1

I’m an old hand c++/nmake guy, newbie to java/gradle, trying to both RTFM and get my project out the door. My current project requires me to run java build tools to generate source for the main application. I have my build tools in buildSrc, and they build just fine. But the docs seem to suggest that my build tools will somehow magically be on the build classpath; instead to make them work I’m having to resort to this kludge (my ignorance being boundless):

task blah {
   ...
   javaexec {
       classpath = sourceSets.main.compileClasspath + files(currentDir.toString() + '/buildSrc/build/classes/main')
       ...
   }
}

Surely there is a better way…


(James Justinic) #2

Yes, the compiled classes in buildSrc will be added to the build script classpath. This means that you could instantiate or call static methods on these classes from the buildscript. Calling javaexec causes your build to fork a new java process with its own classpath.

If you want to actually use your build tool in a more typical buildSrc way, you’d probably want to implement a task that called the operation in your build tool directly.


(William Zeitler) #3

When I try:

task blah {
   ...
   javaexec {
       //classpath = sourceSets.main.compileClasspath + files(prjCurrentDir.toString() + '/buildSrc/build/classes/main' (THIS WORKS)
       classpath = buildscript.configurations.classpath (THIS DOESN'T WORK)
       ...
   }
}

the build tool fails to run: could not find or load main…