Integration of Java tools


We have some internal java tools to check some rules which would like to integrate in Gradle. These tools are callable via a static main method, and deliver the result of the program via standard out.

Are there any guidelines how to integrate such a tool into Gradle? Something like best practices

  • whether to run the program in its own process?
  • how to listen to standard out?
  • is it useful to use a class implementing VerificationTask and Reporting?
  • is it better to refactor the tools to have a Java API?

Thanks for any hint,

Not really. You can take a look at some of the implementations for similar plugins in Gradle core (PMD, Checkstyle, Findbugs, etc) but you’ll likely realize that many of them actually just call out to Ant tasks.

Depends on your tool. I’d say probably not, unless it absolutely needs to be isolated from the current process. However in your case you may have to (see below).

If your exiting code simply writes to stdout then you might be stuck with executing in a separate process. You can use the JavaExec task for this (or the javaExec() method), which supports capturing stdout in something like a ByteArrayOutputStream.

Not really. Implementing reporting would allow your tasks’ reports to show up when using the build dashboard plugin but that’s about it. It’s also non-trivial to implement the Reporting interface as you need to also provide a working implementation for ReportContainer.

Perhaps, as it might make it easier to produce reports in multiple outputs. If you can get the diagnostic information you need by simply capturing stdout then I probably wouldn’t bother.

Thanks for your elaborated answer. In this case, I will integrate it via javaExec().

As I want to run my new task in the check-task, I simply make a dependency from the check task to my task or is there a more gradle-way to do that?

Having check depend on your task is the correct way to approach this.