Strange Compile error with Gradle 2.5 and Jdk1.7

Today I downloaded Gradle 2.5 and did a full build on our project. What is really surprising to me is a build failure due to a compile error - which is not produced using Gradle 2.4!

This is the output:

:de.uvdms.ui.main:compileJava
Q:\sources\trunk_clf\uvdms\de.uvdms.ui.main\src\main\java\de\uvdms\ui\core\jetty\webapp\FavWSSpringS
ervlet.java:36: error: try-with-resources not applicable to variable type
try (ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getInitParameter(
“contextfile”))) {
^
required: AutoCloseable
found: ClassPathXmlApplicationContext
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
:de.uvdms.ui.main:compileJava FAILED

Please note, Gradle settings and compile settings did not change. The only thing I’m changing in my environment is the path to GRADLE_HOME.

GRADLE_HOME=D:\Java\gradle-2.5
GRADLE_OPTS=-Dorg.gradle.daemon=true -Dorg.gradle.java.home=D:\java\jdk1.7 -Dorg.gradle.deprecation.
trace=true
GRADLE_USER_HOME=Q:\gradleCache

I understand this is an error produced by compiler. But somehow this must be triggered by Gradle, because using the same compiler and Gradle 2.4 does not produce a compile error.

So nobody else had this problem with Gradle 2.5.

Any tips what might be the cause of this?

What version of the Spring Framework are you trying to depend on and what version is ending up in your compile classpath? ClassPathXmlApplicationContext did not implement AutoCloseable until Spring 3.2.0.RELEASE, which is required for the try-with-resources syntax as mentioned in the compile error.

Check that the spring-context dependency on your compile classpath is >= 3.2.0.RELEASE and if you see a difference between the version resolved with Gradle 2.4 and Gradle 2.5. Ordering might also be important if there’s some way that you have more than one version on the compile classpath.

We are using Spring ‘‘4.1.6.RELEASE’’.

But, wait, Justinic brought me an idea. Wenn I list the dependencies of the subproject where the error occurs, I get this:

±-- org.jvnet.jax-ws-commons.spring:jaxws-spring:1.8
| ±-- org.springframework:spring:2.0
| ±-- org.springframework:spring:2.0
| ±-- org.springframework:spring-core:2.0 -> 4.1.6.RELEASE ()
| ±-- org.springframework:spring-core:2.0 -> 4.1.6.RELEASE (
)
| ±-- org.springframework:spring-context:2.0 -> 4.1.6.RELEASE ()
| ±-- org.springframework:spring-context:2.0 -> 4.1.6.RELEASE (
)
| ±-- org.apache.xbean:xbean-spring:2.7
| | — org.springframework:spring:1.2.4 -> 2.0 ()
| | — org.springframework:spring:1.2.4 -> 2.0 (
)

Obivously there is a route from jaxws-spring to org.springframework:spring:2.0!!! Maybe here is the culprit?

Fine, fine, fine. I found there is a newer version (1.9) of jaxws-spring. Then, when I changed to this newer version, everythings compiled. And the dependency graph now looks as this:

±-- org.jvnet.jax-ws-commons.spring:jaxws-spring:1.9
| ±-- javax.xml.ws:jaxws-api:2.2.8
| | ±-- javax.xml.bind:jaxb-api:2.2.4 -> 2.2.7
| | ±-- javax.xml.soap:saaj-api:1.3.4
| | | — javax.activation:activation:1.1
| | ±-- org.glassfish:javax.annotation:3.1.1
| | — javax.jws:jsr181-api:1.0-MR1
| ±-- com.sun.xml.ws:jaxws-rt:2.2.8-promoted-b146
| | ±-- javax.xml.bind:jaxb-api:2.2.7
| | ±-- javax.xml.ws:jaxws-api:2.2.8 ()
| | ±-- javax.xml.soap:saaj-api:1.3.4 (
)
| | ±-- com.sun.xml.bind:jaxb-impl:2.2.7-b41
| | ±-- com.sun.xml.ws:policy:2.3.1
| | ±-- org.glassfish.gmbal:gmbal-api-only:3.1.0-b001
| | | — org.glassfish.external:management-api:3.0.0-b012
| | ±-- org.jvnet.staxex:stax-ex:1.7.1
| | ±-- com.sun.xml.stream.buffer:streambuffer:1.5
| | | — org.jvnet.staxex:stax-ex:1.7 -> 1.7.1
| | ±-- org.jvnet.mimepull:mimepull:1.8
| | ±-- com.sun.xml.fastinfoset:FastInfoset:1.2.12
| | ±-- org.glassfish.ha:ha-api:3.1.8
| | ±-- com.sun.xml.messaging.saaj:saaj-impl:1.3.19
| | | — org.jvnet.mimepull:mimepull:1.7 -> 1.8
| | ±-- org.codehaus.woodstox:woodstox-core-asl:4.1.2
| | | — org.codehaus.woodstox:stax2-api:3.1.1
| | — org.codehaus.woodstox:stax2-api:3.1.1
| ±-- javax.servlet:servlet-api:2.5
| ±-- org.springframework:spring-core:3.2.3.RELEASE -> 4.1.6.RELEASE ()
| ±-- org.springframework:spring-beans:3.2.3.RELEASE -> 4.1.6.RELEASE (
)
| ±-- org.springframework:spring-context:3.2.3.RELEASE -> 4.1.6.RELEASE ()
| ±-- org.springframework:spring-web:3.2.3.RELEASE -> 4.1.6.RELEASE (
)

I hit a similar issue but the dependency output is the same (2.4 vs 2.5). I wonder if the default JavaCompile options have changed?

Update: using the -d option and can see the ordering of the classpath is completely different between versions. This must have exposed a class conflict I was not aware of.

Somehow, this whole thing stays mysterious. Because of some other dependency conditions (JAX WS), I’ve found, that I cannot use " a newer version (1.9) of jaxws-spring", but had to stay with this version 1.8, which I thought was the culprit of my compile problem with Gradle 2.5.

Now, the compile works with jax-ws-spring-1.8. Don’t know why.

I resolved the “mystery” by explicitely including our Spring-version in the dependency graph; somehow this is forcing the version and therefore overriding the dependencies jaxws-spring declares.