title: Best way to define javah task in gradle
body: <p>I'm fairly new to gradle and groovy. Here is my task that generates JNI headers:</p>
  
  <pre><code>apply plugin: 'java'
  apply plugin: 'application'
  
  mainClassName = "com.my.example.HelloG"
  
  task GenerateJniHeaders(dependsOn: 'classes') &lt;&lt; {
      def classpath = "build/classes/main"
      def nativeIncludes = "src/native/include"
      "javah -d ${nativeIncludes} -classpath ${classpath} ${mainClassName}".execute()
  }
  classes.finalizedBy GenerateJniHeaders
  build.dependsOn GenerateJniHeaders
  </code></pre>
  
  <p>It works ok but I feel it's a bit ugly. How can I improve it? I appreciate any suggestions, especially those which help me remove variables hardcoded by me. I would also like to make this task more generic - now it only generates JNI header for main class but I would want to run it for all java files.
  Moreover when this task fails (e.g. classpath is wrong) it doesn't print any error message and build succeed, which is misleading.</p>