Adding classes built by one task to the classpath when executing a downstream task

(Tim Dudgeon) #1

Hi, I have one gradle task that compiles some groovy classes, and have another task that then uses those compiled classes to do some work. How do I add those compiled classes to the runtime classpath of the downstream task? Currently I get an ‘Unable to resolve class’ error. Thanks Tim

(Peter Niederwieser) #2

Is the downstream task trying to execute those classes?

(Tim Dudgeon) #3

Exactly. Something like this:

task downsteamTask(dependsOn: compileUpstreamTask) << {

def runner = new com.somewhere.something.MyRunner() }

(Peter Niederwieser) #4

Depending on your exact needs, you could either use a JavaExec task or move the classes to be compiled into the buildSrc project. In the latter case, Gradle will automatically put them on the build script class path.

(Luke Daley) #5

Here are some docs on the buildSrc approach, which is the recommended way.

(Tim Dudgeon) #6

Hi Peter, Luke,

Thanks for the help. I got the buildSrc project approach working nicely.