<NME> build.gradle
<BEF> apply plugin: 'java'

dependencies {
    compile 'org.apache.openjpa:openjpa:2.3.0'
}

task buildMetaModel << {
    println "Building metamodel"
}


task enhance << {
    ant.taskdef(
        name      : 'openJPAEnhancer',
        classpath : project.runtimeClasspath.asPath,
    testImplementation(project(":genie-test"))
}
}

compileJava {
    dependsOn("buildMetaModel")
}

jar {
    dependsOn enhance
}

<MSG> Have dynamic generation of metamodel classes working however it's not as nice as I'd like as it still dumps the generated classes directly into src/main instead of a generated folder. Couldn't get generated folder to work yet. Will have to come back to it when have more time but need to move on right now

<DFF> @@ -1,15 +1,33 @@
 apply plugin: 'java'
 
+def metaModelIgnorePattern = '**/com/netflix/genie/common/model/*_.java'
+
+//sourceSets {
+//    generated {
+//        java {
+//            srcDirs = ['src/generated-sources/java']
+//        }
+//        compileClasspath += sourceSets.main.allJava
+//    }
+//}
+
 dependencies {
     compile 'org.apache.openjpa:openjpa:2.3.0'
 }
 
-task buildMetaModel << {
-    println "Building metamodel"
+task genJPAMetaModel(type: JavaCompile, group: 'build', description: 'Generate JPA metamodels') {
+    source = sourceSets.main.java
+    classpath = configurations.compile
+    options.compilerArgs = [
+        "-proc:only",
+        "-Aopenjpa.metamodel=true"
+    ]
+    //destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
+    destinationDir = sourceSets.main.java.srcDirs.iterator().next()
+    dependencyCacheDir = compileJava.dependencyCacheDir
 }
 
-
-task enhance << {
+task enhance(description: "Enhance model classes for use with JPA") << {
     ant.taskdef(
         name      : 'openJPAEnhancer',
         classpath : project.runtimeClasspath.asPath,
@@ -22,9 +40,33 @@ task enhance << {
 }
 
 compileJava {
-    dependsOn("buildMetaModel")
+    dependsOn genJPAMetaModel
+    //source += sourceSets.generated.java
 }
 
 jar {
     dependsOn enhance
+}
+
+clean {
+    //delete 'src/generated-sources'
+    //delete 'src/main/java/com/netflix/genie/common/model/*_.java'
+    delete sourceSets.main.allJava.matching {
+        include metaModelIgnorePattern
+    }
+}
+
+//Ignore the generated classes from all our style/coverage/bug finding tools
+tasks.withType(Checkstyle) {
+    exclude metaModelIgnorePattern
+}
+
+tasks.withType(FindBugs) {
+    classes = classes.filter {
+        !it.path.contains("_")
+    }
+}
+
+tasks.withType(Pmd) {
+    exclude metaModelIgnorePattern
 }
\ No newline at end of file

Have dynamic generation of metamodel classes working however it's not as nice as I'd like as it still dumps the generated classes directly into src/main instead of a generated folder. Couldn't get generated folder to work yet. Will have to come back to it when have more time but need to move on right now