Strange problem of Gradle compare with Maven


(Seto) #1

compile group: ‘org.wildfly.swarm’, name: ‘jaxrs-multipart’, version: ‘2017.5.0’

io.undertow.undertow-servlet is resolved as version 1.2.9.Final.

<dependency>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>jaxrs-multipart</artifactId>
  <version>2017.5.0</version>
</dependency>

At the same time, for Maven, io.undertow.undertow-servlet is resolved as version 1.4.11.Final.

I also tried clear the .gradle folder.


(uklance) #2

Maven uses a “nearest definition wins” strategy to resolve multiple versions of the same dependency. If two poms in the hierarchy declare the same dependency the “closest” definition wins. Gradle will use the latest version by default but also allows custom resolution strategies to overridde this behaviour

You could try

gradle dependencies

and

mvn dependency:tree

From command line to get a better picture of what’s going on


(Seto) #3

But the version is not latest in the Gradle.

https://repo1.maven.org/maven2/org/wildfly/swarm/wildfly-swarm/2017.5.0/wildfly-swarm-2017.5.0.pom
imports
https://repo1.maven.org/maven2/org/wildfly/core/wildfly-core-parent/2.2.1.Final/wildfly-core-parent-2.2.1.Final.pom
https://repo1.maven.org/maven2/org/wildfly/wildfly-parent/10.1.0.Final/wildfly-parent-10.1.0.Final.pom
And the version in the wildfly-core-parent is correct. But for from the wildfly-parent, there’re multiple versions in it.


(Seto) #4

1.2.9.Final is absolutely not the newest.
https://docs.gradle.org/current/userguide/dependency_management.html#sub:version_conflicts
The document claims that Gradle will resolve the newest.


(Seto) #5

And also, failOnVersionConflict won’t give me all the conflict. It will only give me one. After I add the “force” in the “resolutionStrategy”. It won’t fail on the other conflicts.


(uklance) #6

I notice there’s a <profile> section with various <activation> types. Gradle only has limited support for maven profiles. Perhaps the version is declared in a profile which is ignored be gradle

See support for maven pom profiles and issue-with-gradle-build-and-pom-parsing


(Seto) #7

No. I’m sure the version is declared in this https://repo1.maven.org/maven2/org/wildfly/core/wildfly-core-parent/2.2.1.Final/wildfly-core-parent-2.2.1.Final.pom.
And it’s imported by this https://repo1.maven.org/maven2/org/wildfly/swarm/wildfly-swarm/2017.5.0/wildfly-swarm-2017.5.0.pom.

I’m migrating a plugin for WildFly Swarm in Maven to Gradle. But I found that it’s working incorrectly. After a deep inspection in the problem. I found that some dependencies are resolved as older version. And it breaks the plugin.


(Seto) #8

Why is the newest version resolve strategy not working? If it’s working. I think it would solve my problem.
Or is there a way to find out all the version conflict?
The failOnVersionConflict will only return the first one


(Seto) #9
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.2.Final'
compile group: 'org.jboss.resteasy', name: 'resteasy-multipart-provider', version: '3.1.2.Final'
compile group: 'org.wildfly.swarm', name: 'jaxrs-multipart', version: '2017.5.0'

Just about these 3 lines of dependencies.

There’s 2 dependencies are resolved to incorrect version number. And it breaks the logic of WildFly Swarm plugin classpath.

group: ‘org.apache.httpcomponents’, name: ‘httpcore’, version: ‘4.4.5’

This should be 4.4.5 based on https://repo1.maven.org/maven2/org/jboss/resteasy/resteasy-dependencies/3.1.2.Final/resteasy-dependencies-3.1.2.Final.pom.

group: ‘io.undertow’, name: ‘undertow-servlet’, version: ‘1.4.11.Final’

This should be 1.4.11.Final based on https://repo1.maven.org/maven2/org/wildfly/core/wildfly-core-parent/2.2.1.Final/wildfly-core-parent-2.2.1.Final.pom

The pom is by the JBoss team. And it’s working with Maven. And they said that the community shows less interest at Gradle. As a gradle user, after a week of migrating the plugin from Maven to Gradle. I found this problem absolutely block my work. I can absolutely add two lines of dependencies to force the version. But if the module is updated. Then I have to pay a week again to find out the problem.

So, please help me. For a user that shows interest in Gradle.


(Seto) #10

I’ve finished the migrating of the plugin. But blocking here by the dependency version conflict resolving.


(uklance) #11

Please do the following

  1. Create a simple build.gradle with the single dependency
  2. Run gradle dependencies from command line
  3. Create a simple pom.xml with the single dependency
  4. Run mvn dependency:tree from command line
  5. Paste the results here

(Seto) #12

https://gist.github.com/SetoKaiba/25ae12d31891f5935b742f3565dd5874
Here’s the example. You can see the different undertow-servlet version.


(uklance) #13

Ok, so looking at both dependency trees I can see that undertow-servlet is coming from org.wildfly.swarm:undertow:2017.5.0 in both instances.

Gradle

     |    +--- org.wildfly.swarm:undertow:2017.5.0
     |    |    +--- org.wildfly.swarm:container:2017.5.0 (*)
     |    |    +--- org.wildfly.swarm:io:2017.5.0
     |    |    |    +--- org.wildfly.swarm:container:2017.5.0 (*)
     |    |    |    \--- org.wildfly.swarm:logging:2017.5.0 (*)
     |    |    +--- org.wildfly.swarm:logging:2017.5.0 (*)
     |    |    +--- org.wildfly.swarm:ee:2017.5.0
     |    |    |    +--- org.wildfly.swarm:container:2017.5.0 (*)
     |    |    |    +--- org.wildfly.swarm:logging:2017.5.0 (*)
     |    |    |    +--- org.wildfly.swarm:naming:2017.5.0
     |    |    |    |    +--- org.wildfly.swarm:spi:2017.5.0 (*)
     |    |    |    |    +--- org.wildfly.swarm:container:2017.5.0 (*)
     |    |    |    |    \--- org.wildfly.swarm:logging:2017.5.0 (*)
     |    |    |    +--- org.jboss.spec.javax.enterprise.concurrent:jboss-concurrency-api_1.0_spec:1.0.0.Final
     |    |    |    +--- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec:1.0.0.Final
     |    |    |    +--- org.jboss.spec.javax.el:jboss-el-api_3.0_spec:1.0.7.Final
     |    |    |    \--- org.glassfish:javax.el-impl:3.0.1-b08-jbossorg-1
     |    |    +--- org.wildfly.swarm:request-controller:2017.5.0
     |    |    |    +--- org.wildfly.swarm:container:2017.5.0 (*)
     |    |    |    \--- org.wildfly.swarm:logging:2017.5.0 (*)
     |    |    +--- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-jboss:2.0.0-alpha-9 (*)
     |    |    +--- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-jboss:2.0.0-alpha-9 (*)
     |    |    +--- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-javaee:2.0.0-alpha-9 (*)
     |    |    +--- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-javaee:2.0.0-alpha-9 (*)
     |    |    +--- org.ow2.asm:asm-all:5.0.4
     |    |    +--- org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec:1.0.0.Final
     |    |    +--- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:1.1.1.Final
     |    |    +--- io.undertow:undertow-servlet:1.2.9.Final

Maven

[INFO]    |  +- org.wildfly.swarm:undertow:jar:2017.5.0:compile
[INFO]    |  |  +- org.wildfly.swarm:io:jar:2017.5.0:compile
[INFO]    |  |  +- org.wildfly.swarm:ee:jar:2017.5.0:compile
[INFO]    |  |  |  +- org.wildfly.swarm:naming:jar:2017.5.0:compile
[INFO]    |  |  |  +- org.jboss.spec.javax.enterprise.concurrent:jboss-concurrency-api_1.0_spec:jar:1.0.0.Final:compile
[INFO]    |  |  |  +- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec:jar:1.0.0.Final:compile
[INFO]    |  |  |  +- org.jboss.spec.javax.el:jboss-el-api_3.0_spec:jar:1.0.7.Final:compile
[INFO]    |  |  |  \- org.glassfish:javax.el-impl:jar:3.0.1-b08-jbossorg-1:compile
[INFO]    |  |  +- org.wildfly.swarm:request-controller:jar:2017.5.0:compile
[INFO]    |  |  +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-jboss:jar:2.0.0-alpha-9:compile
[INFO]    |  |  +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-jboss:jar:2.0.0-alpha-9:compile
[INFO]    |  |  +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-javaee:jar:2.0.0-alpha-9:compile
[INFO]    |  |  |  \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-base:jar:2.0.0-alpha-9:compile
[INFO]    |  |  +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-javaee:jar:2.0.0-alpha-9:compile
[INFO]    |  |  |  \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-base:jar:2.0.0-alpha-9:compile
[INFO]    |  |  |     \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-spi:jar:2.0.0-alpha-9:compile
[INFO]    |  |  +- org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec:jar:1.0.0.Final:compile
[INFO]    |  |  +- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.1.Final:compile
[INFO]    |  |  \- io.undertow:undertow-servlet:jar:1.4.11.Final:compile

Trying to follow it through by eye. I can’t see where the version for undertow-servlet is specified. Can you???

wildfly-swarm pom.xml

<parent>
   <groupId>org.wildfly.swarm</groupId>
   <artifactId>wildfly-swarm</artifactId>
   <version>2017.5.0</version>
   <relativePath>../../../</relativePath>
</parent>
...
<dependency>
   <groupId>io.undertow</groupId>
   <artifactId>undertow-servlet</artifactId>
   <!-- no version declared here... must be in <dependencyManagement> in a parent -->
</dependency>

wildfly-swarm pom.xml

<parent>
   <groupId>org.wildfly.swarm</groupId>
   <artifactId>parent</artifactId>
   <version>8</version>
</parent>
...
<dependencyManagement>
   <!-- no mention of undertow-servlet here -->
</dependencyManagement>

parent pom.xml

<parent>
   <groupId>org.jboss</groupId>
   <artifactId>jboss-parent</artifactId>
   <version>21</version><relativePath/>
</parent>
...
<dependencyManagement>
   <!-- no mention of undertow-servlet here -->
</dependencyManagement>

jboss-parent pom.xml

<dependencyManagement>
   <!-- no mention of undertow-servlet here -->
</dependencyManagement>

(uklance) #14

I think something is getting mixed up with the version.io.undertow property. I cleared my maven repository and loaded your simple pom.xml.

The only reference to 1.2.9.Final is in wildfly-core-parent-1.0.1.Final.pom

<version.io.undertow>1.2.9.Final</version.io.undertow>
...
   <dependency>  
      <groupId>io.undertow</groupId>
      <artifactId>undertow-servlet</artifactId>
      <version>${version.io.undertow}</version>

And it looks like 1.4.11.Final is coming from wildfly-core-parent-2.2.1.Final.pom

<version.io.undertow>1.4.11.Final</version.io.undertow>
...
   <dependency>  
      <groupId>io.undertow</groupId>
      <artifactId>undertow-servlet</artifactId>
      <version>${version.io.undertow}</version>

I still don’t fully understand how this actually fits into the pom hierarchy. But perhaps one property value is “winning” in Gradle and another is “winning” in Maven.


(Seto) #15

Here I can list multiple versions that I can find.
At least I can find 1.4.11.Final, 1.2.6.Final and 1.3.0.Beta6. But the nearest strategy gives the correct result of 1.4.11.Final. This problem is blocking me the migration of the WildFly Swarm Gradle Plugin from Maven.
I’m not the member of team WildFly Swarm. And I can’t change the poms. And I can force the dependency version to temporarily solve the problem. But if the WildFly Swarm is updated. Then the plugin will be broken again.

https://repo1.maven.org/maven2/org/wildfly/swarm/jaxrs-multipart/2017.5.0/jaxrs-multipart-2017.5.0.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm</artifactId>
<version>2017.5.0</version>
<relativePath>../../../</relativePath>
</parent>

https://repo1.maven.org/maven2/org/wildfly/swarm/wildfly-swarm/2017.5.0/wildfly-swarm-2017.5.0.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wildfly.swarm</groupId>
<artifactId>parent</artifactId>
<version>8</version>
</parent>
<artifactId>wildfly-swarm</artifactId>
<version>2017.5.0</version>
<name>Root</name>
<description>Root</description>
<packaging>pom</packaging>
...
<properties>
...
<version.wildfly>10.1.0.Final</version.wildfly>
<version.org.wildfly.core>2.2.1.Final</version.org.wildfly.core>
...
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-core-parent</artifactId>
<type>pom</type>
<version>${version.org.wildfly.core}</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-parent</artifactId>
<version>${version.wildfly}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

https://repo1.maven.org/maven2/org/wildfly/core/wildfly-core-parent/2.2.1.Final/wildfly-core-parent-2.2.1.Final.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>20</version>
</parent>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-core-parent</artifactId>
<version>2.2.1.Final</version>
<name>WildFly: Core Parent Aggregator</name>
<description>WildFly: Core Parent Aggregator</description>
<packaging>pom</packaging>
...
<properties>
...
<version.io.undertow>1.4.11.Final</version.io.undertow>
...
</properties>
...
<dependencyManagement>
<dependencies>
...

<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>${version.io.undertow}</version>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-build-config</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${version.io.undertow}</version>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-build-config</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.servlet.jsp</groupId>
<artifactId>jboss-jsp-api_2.2_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-websockets-jsr</artifactId>
<version>${version.io.undertow}</version>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-build-config</artifactId>
</exclusion>
</exclusions>
</dependency>

https://repo1.maven.org/maven2/org/wildfly/wildfly-parent/10.1.0.Final/wildfly-parent-10.1.0.Final.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>20</version>
</parent>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-parent</artifactId>
<version>10.1.0.Final</version>
<name>WildFly: Parent Aggregator</name>
<description>WildFly: Parent Aggregator</description>
<packaging>pom</packaging>
...
<properties>
...
<version.io.undertow.jastow>2.0.1.Final</version.io.undertow.jastow>
<version.io.undertow.js>1.0.2.Final</version.io.undertow.js>
...

<version.org.jboss.ws.jaxws-undertow-httpspi>1.0.1.Final</version.org.jboss.ws.jaxws-undertow-httpspi>
</properties>
...
<dependencyManagement>
<dependencies>

<dependency>
<groupId>io.undertow.jastow</groupId>
<artifactId>jastow</artifactId>
<version>${version.io.undertow.jastow}</version>
</dependency>
<dependency>
<groupId>io.undertow.js</groupId>
<artifactId>undertow-js</artifactId>
<version>${version.io.undertow.js}</version>
</dependency>

https://repo1.maven.org/maven2/io/undertow/jastow/jastow/2.0.1.Final/jastow-2.0.1.Final.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>16</version>
</parent>
<groupId>io.undertow.jastow</groupId>
<artifactId>jastow</artifactId>
<version>2.0.1.Final</version>
<name>Jastow</name>
<description>JSP 2.3 container</description>
<properties>
...
<version.io.undertow>1.2.6.Final</version.io.undertow>
...
</properties>
...
<dependencies>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${version.io.undertow}</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
<version>${version.io.undertow}</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<type>test-jar</type>
<scope>test</scope>
<version>${version.io.undertow}</version>
</dependency>

https://repo1.maven.org/maven2/io/undertow/js/undertow-js/1.0.2.Final/undertow-js-1.0.2.Final.pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>19</version>
</parent>
<groupId>io.undertow.js</groupId>
<artifactId>undertow-js</artifactId>
<version>1.0.2.Final</version>
<name>Undertow Javascript API</name>
<properties>
...
<version.io.undertow>1.3.0.Beta6</version.io.undertow>
...
</properties>
<dependencies>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>${version.io.undertow}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${version.io.undertow}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-websockets-jsr</artifactId>
<version>${version.io.undertow}</version>
<scope>provided</scope>
</dependency>

(uklance) #16

I can force the dependency version to temporarily solve the problem. But if the WildFly Swarm is updated. Then the plugin will be broken again.

I guess if you had a way of taking the wildfly version (2017.5.0) and getting the undertow version (1.2.9.Final) you’d be happy? You could use an artifact resolution query to get the pom.xml and groovy’s XmlSlurper to retrieve the property value from the xml.


(Seto) #17

Not 1.2.9.Final. But 1.4.11.Final. And I will be happy.


(Seto) #18

I assume that when resolving Maven stuffs use the strategy from Maven. And resolving Gradle inside stuffs use the strategy from Gradle would be better. Because they will define the pom in the Maven way.


(uklance) #19

Agreed, that pom hierarchy is so complex that I still don’t fully understand how the undertow version is decided. I think there’s some edge case here where maven and gradle are resolving it differently. It’s probably worth raising an issue on gradle’s github repository

My artifact resolution query + XmlSlurper solution is a quick fix hack to let you move on


(uklance) #20

I created an issue on github here