I'm creating a build process with Gradle and I want to provide a plugin that uses Java code. The Gradle plugin documentation says this is possible:
You can implement a custom plugin in any language you like, provided the implementation ends up compiled as bytecode. For the examples here, we are going to use Groovy as the implementation language. You could use Java or Scala instead, if you want.
However, after multiple hours of Googling and reading, I have yet to find any explanation of how to create a Gradle custom plugin with Java. It seems like you could create the code for it in a directory like:
<rootProjectDir>/buildSrc/src/main/java/
MyGradlePlugin.java
MyGradleTasks.java
But the question then becomes:
- How to implement the plugin class and tasks in Java to be compatible with Gradle?
How to get Gradle to recognize the Java classes and tasks so you can use them in a build?
Can you just reference the plugin class like you do for the Groovy equivalent?
src/main/resources/META-INF/gradle-plugins/myjavaplugin.propertiesimplementation-class=org.me.MyGradlePlugin
I realize that I could just call the Java code with project.javaexec or JavaExec, but I'm concerned this will make my build process less portable.