Hi,
we want to use generated JPA models (from hibernate metamodel generator) but checkstyle, findbugs & friends shall not check those files.
For this we added a new sourceSet “generated”, that allows us to exclude all files from checkstyle & co. Unfortunately, we cannot use the generated classes in our application as they’re not in the main sourceSets classpath (compileJava complains with “cannot find symbol” referring to some generated class).
Here’s the relevant parts of our build:
sourceSets {
generated {
java { srcDirs = [
"$buildDir/generated-src/main/java"
] }
compileClasspath += sourceSets.main.output
}
}
task generateMetamodel(type: JavaCompile, description: 'Hibernate JPA 2 Static-Metamodel Generator') {
source = sourceSets.main.java
classpath = configurations.compile + configurations.jpamodelgen
options.compilerArgs = [
"-proc:only",
"-AaddGenerationDate=true",
]
destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}
compileJava.dependsOn generateMetamodel
checkstyleGenerated { exclude '**/*' }
findbugsGenerated { exclude '**/*' }
pmdGenerated { exclude '**/*' }
When we add the generated sources to the compile java sources (via “compileJava.source(sourceSets.generated.java, sourceSets.main.java)”), compilation (with references to generated classes) works, but unfortunately checkstyle & co then also check these generated sources and reports lots of errors.
When we try to add the generated sources output to the compile classpath (via “compileJava.classpath += sourceSets.generated.output”) compileJava fails with a circular dependency error:
Circular dependency between the following tasks:
:connect-webapp:classes
\--- :connect-webapp:compileJava
\--- :connect-webapp:generatedClasses
\--- :connect-webapp:compileGeneratedJava
\--- :connect-webapp:classes (*)
Is there any way to keep generated sources in a separate sourceSet (to be able to exclude them completely from checkstyle & co) and add the compiled, generated classes to the compileJava classpath?