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

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

Is the downstream task trying to execute those classes?

Exactly. Something like this:

task downsteamTask(dependsOn: compileUpstreamTask) << {

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

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.

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

Hi Peter, Luke,

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