title: Generate a Java class using Gradle for Java plugin
body: <p>I'd like to generate a Java class using a Gradle task for a <strong>Java</strong> project, similar to how the Android plugin creates <code>BuildConfig.java</code> using the <code>buildConfig &lt;String&gt;</code> notation, e.g.:</p>
  
  <pre><code>android {
      ...
  
      buildTypes {
          final String PROVIDER_AUTHORITY_RELEASE = "public static final String PROVIDER_AUTHORITY = \"com.example.project.ContentProvider\";\n";
          final String PROVIDER_AUTHORITY_DEBUG = "public static final String PROVIDER_AUTHORITY = \"com.example.project.debug.ContentProvider\";\n";
  
          debug {
              ...
              buildConfig PROVIDER_AUTHORITY_DEBUG
          }
  
          release {
              ...
              buildConfig PROVIDER_AUTHORITY_RELEASE
          }
      }
  }
  </code></pre>
  
  <p>The use case is that I'm developing an open source app which requires the use of an API key and secret; I have the key and secret in <code>gradle.properties</code> which isn't committed to my VCS.</p>
  
  <p>So far, I have this:</p>
  
  <pre><code>task generateSources {
      outputDir = file("$buildDir/../src/main/java/uk/co/ataulm/mijur/core/api")
      outputs.dir outputDir
      doFirst {
          outputDir.exists() || outputDir.mkdirs()
  
          String API_CLIENT_ID = "public static final String API_CLIENT_ID = \"&lt;your imgur uk.co.ataulm.mijur.core.api client id&gt;\";\n"
          String API_CLIENT_SECRET = "public static final String API_CLIENT_SECRET = \"&lt;your imgur uk.co.ataulm.mijur.core.api client secret&gt;\";\n"
  
          try {
              API_CLIENT_ID = "public static final String API_CLIENT_ID = \"" + apiClientId + "\";\n"
              API_CLIENT_SECRET = "public static final String API_CLIENT_SECRET = \"" + apiClientSecret + "\";\n"
          } catch (Exception e) {
              println "gradle.properties not set with apiClientId and/or apiClientSecret. API calls will not work.";
          }
  
          new File(outputDir, "ApiConstants.java").write("package uk.co.ataulm.mijur.core.api;\n\npublic class ApiConstants {\n" + "    " + API_CLIENT_ID + "    " + API_CLIENT_SECRET + "}")
      }
  }
  
  compileJava.source generateSources.outputs.files, sourceSets.main.java
  </code></pre>
  
  <p>and it works - it generates that file at the specified location. But it's very fragile; explicitly naming the package is prone to error. I'd be happy if the file is generated in some other package (e.g. at the root of the <code>src/main/java</code>) as long as I can access it in Java, using <code>MyGeneratedFile.MyConstant</code>.</p>
  
  <p>Appreciate any ideas (even if they are down a different track).</p>