Uyen_Vu
(uyentvu)
January 20, 2012, 7:08pm
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
sourceSets.main.java
{
srcDir generatedDir
}
Any help would be greatly appreciated.
Thanks!
Rene
(René Groeschke)
January 20, 2012, 7:19pm
2
Hello Uyen, With the snippet above, you defined two directories for the same source set (here: main.java). Since a sourceset is compiled at once, you have to split the compilation of the generated java code and the other java code. See http://gradle.org/docs/current/userguide/java_plugin.html#N118FA for details.
regards, René
Uyen_Vu
(uyentvu)
January 20, 2012, 7:49pm
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:
sourceSets{
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.
Thanks.
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 {
dependsOn(mySourceGeneratingTask)
options.warnings = false
}
Uyen_Vu
(uyentvu)
January 23, 2012, 11:50am
5
Peter,
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.
Thanks.
Uyen_Vu
(uyentvu)
January 23, 2012, 11:53am
6
Peter,
Also, does “compileGeneratedJava” task get called automatically? or I have to do as follows:
compileJava.dependsOn compileGeneratedJava
Thanks in advance.
You shouldn’t need to add a task dependency manually. Gradle should be able to figure it out based on the compile class path.
In 1.0-m3 it has to be ‘compileClasspath += sourceSets.generated.classes’.
Uyen_Vu
(uyentvu)
January 23, 2012, 1:27pm
9
Peter,
I would like to personally thank you for your help. It works now. This forum is great.
Regards,
Uyen_Vu
(uyentvu)
January 23, 2012, 8:23pm
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?
Thanks.
Uyen_Vu
(uyentvu)
January 24, 2012, 1:29pm
11
I figured it out…
test {
runtimeClasspath += sourceSets.generated.classes
}
Thanks anyway…