How can I use a compiled class in a task?


(Charles Anthony) #1

I have a simplish gradle java project that’s successfully compiling and testing my java classes.

I’d now like to create a task in the same gradle project that has those compiled classes on it’s class path, in order to use them in the task itself.

What’s the best way to do this?

There isn’t a “Main Class” that I want to invoke, (and I don’t want to add one in the main source tree unless it’s unavoidable), so using a simple JavaExec task appears (at first glance) to be out .

I’d “simply” like to add the compiled stuff to the tasks class path, and then be able to access those classes via groovy in the body of the task itself.

e.g.

task custom(dependsOn:'compile') {

   doLast {
     // Do Stuff With The Classes Themselves
   }
}

Is that possible? I suspect it’s not in the way that I am doing it; OK, so what’s the right way to do it?

Cheers,

Charles.