title: Creating a Gradle Custom Plugin with Java
body: <p>I'm creating a build process with Gradle and I want to provide a plugin that uses Java code. The Gradle <a href="http://www.gradle.org/docs/current/userguide/custom_plugins.html">plugin documentation</a> <em>says</em> this is possible:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code>&lt;rootProjectDir&gt;/buildSrc/src/main/java/
    MyGradlePlugin.java
    MyGradleTasks.java 
  </code></pre>
  
  <p>But the question then becomes:</p>
  
  <ol>
  <li>How to implement the plugin class and tasks in Java to be compatible with Gradle?</li>
  <li><p>How to get Gradle to recognize the Java classes and tasks so you can use them in a build?  </p>
  
  <p>Can you just reference the plugin class like you do for the Groovy equivalent?</p>
  
  <p><strong><code>src/main/resources/META-INF/gradle-plugins/myjavaplugin.properties</code></strong>
  <code>implementation-class=org.me.MyGradlePlugin</code></p></li>
  </ol>
  
  <p>I realize that I could just call the Java code with <code>project.javaexec</code> or <code>JavaExec</code>, but I'm concerned this will make my build process less portable.</p>