CompileJava failed because of Java Generics related code

(k naike) #1


I’m currently trying to move my build process based on Ant to Gradle.

For some of my Java projects, I need to generate a jar file. This jar file will be use by other Java project. When I use Ant to create the Jar file (via the Ant Jar task), it’s OK, no compilation errors.

But When I try to use Gradle, for some projects, I’ve got some compilation errors like:

error: type argument MyPanel is not within bounds of type-variable T
private void setDefaultValue(MyList<MyPanel> ps) {
    where T is a type-variable: T extends APanel<?> declared in class MyList
Execution failed for task ':compileJava'.
 Compilation failed; see the compiler error output for details.

The --stacktrace option give no additional information. So, Gradle compilation show me that there are some errors in my code. But this same (old) code (jar by the Ant jar task) is currently used by 20 or more other projects and all it’s OK.

After that (and with some replies to another post), in my Gradle Build, I tried to use the same compiler version used by Ant. But the result is the same: with Ant, it works fine but with Gradle, I’ve got compilation errors (even if I change the source and target compatibility in the build.gradle to match an old JDK)

Moreover, I tried another thing: create the jar lib manually (the project in Eclipse workspace -> Export… -> Jar file). As with Ant, no compilation errors (only warnings but none of them concerning the previous generics problems).

Gradle seems to be a great Build tool, so I would like to understand why this (compilation errors) happening when I use Gradle compileJava task.

Thank in advance for any help or explanations.

(Peter Niederwieser) #2

Can you provide a self-contained reproducible example that demonstrates the problem? Otherwise, it will be difficult to help. Which JDK do you use with Ant, and what is the output of ‘gradle -v’?

PS: Just to be clear, it wouldn’t be enough to use the same source/target level for Ant and Gradle. You’d have to use the exact same JDK version.

(k naike) #3

I’m sorry but I can’t provide any more code because it’s a kind of private framework of my firm.

But, here is the result of the gradle -v:

Gradle 1.6
  Gradle build time: mardi 7 mai 2013 09 h 12 UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_38 (Sun Microsystems Inc. 20.13-b02)
OS: Linux 3.5.0-31-generic amd64

Because of the JAVA_HOME environment variable, Ant is using this same version.

Also, I tried to switch to/from the open-jdk-1.7 but no effects.

I can’t understand why this compilation errors happen with gradle compileJava. Is it possible that the Ant jar task (and the export operation in eclipse) add some stuff to skip this kind of compilation errors?

Or maybe I miss something in my gradle build.

(Peter Niederwieser) #4

I recommend you try to isolate the problem and provide a simplified, reproducible example. You can also try ‘compileJava.options.useAnt = true’. It’s deprecated but still works in 1.x.

(k naike) #5

After hours of investigation, I found the answer to my problem. It was linked to our old way to generate the Jar with Ant. The Ant jar task only put all .class from the bin directory generated by Eclipse into the archive. The problem is that Eclipse seems to ignore all errors that may have in a class. This is why the ant jar task worked. So, in fact, I think all of our old projects need to be updated if we want to use Gradle to build them.

Thank for your help. Gradle is a great tool!!!