How to use gradle as a general purpose workflow tool for processing input data?


Specifically, how to work within the eclipse gradle support when not using gradle to actually build the eclipse project? I’m adding a gradle script to a maven project. Gradle has nothing to do with the project build. I’m writing a gradle script that processes a specific form of data into other formats. The problem is, how to set this up in eclipse so that I can debug the gradle script in eclipse? This is not a “gradle project” in the sense that it’s not using gradle to build it. If I try debug it as a remote java project, it connects, but ignores any breakpoints I have in the script.

Is it even possible to debug a stand-alone gradle script in eclipse?

(Peter Niederwieser) #2

It isn’t currently possible to debug Gradle build scripts in Eclipse. It is, however, possible to debug task and plugin classes (no matter if they are written in Groovy or Java), provided their sources are made known to the Eclipse project used for debugging.


Could you elaborate a bit on “provided their sources are made known to the Eclipse project used for debugging”?

I think I’ve done the above, but still no stopping on break points.

I have a build.gradle:

apply plugin: 'groovy'
apply from: 'buildSrc/src/work/JobApi.groovy'
  dependencies {
 compile gradleApi()
 compile localGroovy()
  task job(type:Exec) {
 JobApi.sendNotification(new URL(jobUrl), 'RUNNING')

and a groovy script that is being loaded because the invocation does work:

  class JobApi {
   static void sendNotification(URL jobUrl, String status) {
  println "sendNotification: ${jobUrl} = ${status}" <- breakpoint set here

What else needs to be done to get eclipse to stop on a breakpoint?

(Peter Niederwieser) #4

I’d expect this to work if the ‘JobApi’ class is located under a configured Eclipse source root. It may be worthwhile to also try with a Java class.


This is turning into the never ending question thread.

I’m assuming I can call a java method directly and not have to use JavaExec right? Any examples of this? Most seem to use JavaExec.

I’ve added::

dependencies {
 compile gradleApi()
 compile localGroovy()
 compile files('build/libs/work.jar') <- from gradle build task

A java class that gets compiled into the above work.jar:

class JobApi2 {
 static void sendNotification(URL jobUrl, String status) {
  System.out.println("sendNotification2: " + jobUrl + " = " + status);

and finally, call it from a task:

task info(dependsOn: build) << { URL(jobUrl), 'RUNNING')

The error I get is:

Could not find property ‘com’ on task ‘:info’.

If I remove the package qualifier, I get:

Could not find property ‘JobApi2’ on task ‘:info’.

Disassembling my java class extracted from work.jar shows:

Compiled from ""
class {;
  static void sendNotification(, java.lang.String);

so it looks like it’s all there.

What else do I need to do to get gradle to recognize this new java class from work.jar?


OK, got the java thing working. Moving it into /buildSrc/main/java from /src/main/java and using the implicit dependencies there worked. It finds the JobApi2 class now and runs it… but still no breakpoint.