How to disable compile warnings for generated classes?

(uyentvu) #1

Hi all,

Does anyone know how to disable warnings when compiling generated classes?

I would like to see compile warnings for my source code only. I do not wish to see compile warnings for generated classes.

Here is my code and it’s not working. I am seeing all compile warnings:

File generatedDir = new File(buildDir.toString() + ‘/generated’)

//Include generated classes in the sourceSets for compilation


srcDir generatedDir


Any help would be greatly appreciated.


(René Groeschke) #2

Hello Uyen, With the snippet above, you defined two directories for the same source set (here: Since a sourceset is compiled at once, you have to split the compilation of the generated java code and the other java code. See for details.

regards, René

(uyentvu) #3

Hi Rene’,

Thanks for your reply.

When you said I have to split the compilation of the generated java code and other java code, you meant to do as below:


main {

java {

srcDir ‘src/java’


java {

srcDir 'buildDir.toString() + ‘/generated’


} }

I read the link you specified but I am still unsure about what to do. If you can give me some code samples, that would be very helpful.


(Peter Niederwieser) #4

A solution based on source sets could look like this:

apply plugin: "java"
  sourceSets {
    generated {
        java.srcDirs = ["$buildDir/generated"]
    main {
        java.srcDirs = ["src/java"]
        compileClasspath += sourceSets.generated.output
  compileGeneratedJava {
    options.warnings = false

(uyentvu) #5


Thanks so much for your response.

I tried your code above and got the following error: Could not find property ‘output’ on source set generated.

I am using Gradle 1.0-milestone-3.


(uyentvu) #6


Also, does “compileGeneratedJava” task get called automatically? or I have to do as follows:

compileJava.dependsOn compileGeneratedJava

Thanks in advance.

(Peter Niederwieser) #7

You shouldn’t need to add a task dependency manually. Gradle should be able to figure it out based on the compile class path.

(Peter Niederwieser) #8

In 1.0-m3 it has to be ‘compileClasspath += sourceSets.generated.classes’.

(uyentvu) #9


I would like to personally thank you for your help. It works now. This forum is great.


(uyentvu) #10

I am running my junit tests and it could not find the path to “generated” sourceSets.

My junit tests depend on sourceSets.generated in the path. Do you know how to specify sourceSets.generated in the runtime path when I run JUnit tests?


(uyentvu) #11

I figured it out…

test {

runtimeClasspath += sourceSets.generated.classes


Thanks anyway…