Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle 6.0 resolves wildcarded maven dependencies differently than Gradle 5.X #10850

Closed
aguibert opened this issue Sep 24, 2019 · 4 comments
Closed

Comments

@aguibert
Copy link

Expected Behavior

I have a working project that has a dependency on a maven artifact produced by a peer component like this:

repositories {
   ivy {
       url "../cnf/local"
   }
}

configurations {
  ejbTools
}

dependencies {
  ejbTools 'test:com.ibm.ws.ejbcontainer.fat_tools:1.+'
}

The complete build.gradle file can be found here: https://github.com/OpenLiberty/open-liberty/blob/master/dev/com.ibm.ws.ejbcontainer.async_fat/build.gradle

Current Behavior

The dependency test:com.ibm.ws.ejbcontainer.fat_tools:1.+ fails to resolve with Gradle 6.0 with the following error:

> Task :com.ibm.ws.ejbcontainer.async_fat:addEJBTools FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/aguibert/dev/git/open-liberty/dev/com.ibm.ws.ejbcontainer.async_fat/build.gradle' line: 32

* What went wrong:
Execution failed for task ':com.ibm.ws.ejbcontainer.async_fat:addEJBTools'.
> Could not resolve all files for configuration ':com.ibm.ws.ejbcontainer.async_fat:ejbTools'.
   > Could not find any matches for test:com.ibm.ws.ejbcontainer.fat_tools:1.+ as no versions of test:com.ibm.ws.ejbcontainer.fat_tools are available.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/test/com.ibm.ws.ejbcontainer.fat_tools/maven-metadata.xml
       - http://public.dhe.ibm.com/ibmdl/export/pub/software/olrepo/test/com.ibm.ws.ejbcontainer.fat_tools/maven-metadata.xml
       - file:/Users/aguibert/dev/git/open-liberty/dev/cnf/local/test/com.ibm.ws.ejbcontainer.fat_tools/
       - file:/Users/aguibert/dev/git/open-liberty/dev/cnf/local/test/com.ibm.ws.ejbcontainer.fat_tools/1.0.33.201909241016/ivy-1.0.33.201909241016.xml
     Required by:
         project :com.ibm.ws.ejbcontainer.async_fat

Context

Currently my project is using Gradle 5.5 and can be built with Java 8, 11, or 12. I am trying to get it working with Java 13 too so I am trying to upgrade to Gradle 6.0.

It seems that there is a general behavior change with the way wildcarded dependencies work in Gradle now (for example com.foo:bar:1.+). My configuration may have been invalid but tolerated in Gradle 5.X, so I'm willing to accept a pointer to a Gradle issue/pr/doc page that describes the behavior change and ideally the steps needed to get around this.

Steps to Reproduce

This will take a while, but you can do:

  1. clone my OpenLiberty repo: https://github.com/aguibert/open-liberty/tree/master
  2. Checkout the java13-gradle-bug-report branch
  3. Run ./gradlew releaseNeeded and it will eventually fail

Your Environment

$ ./gradlew --version

------------------------------------------------------------
Gradle 6.0-20190923093257+0000
------------------------------------------------------------

Build time:   2019-09-23 09:32:57 UTC
Revision:     5b1d0543e4b76fc51aafb5d2fc757dcf086b0e4c

Kotlin:       1.3.50
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          13 (Eclipse OpenJ9 openj9-0.16.0)
OS:           Mac OS X 10.14.6 x86_64
@ljacomet
Copy link
Member

Thanks for trying Gradle 6.0!

This is caused by a breaking change in Gradle 6.0: by default, Gradle no longer resolves dependencies for which the metadata is missing. For a single dependency version, that means no *.pom or ivy.xml. For a dependency with a range, this fails also when the maven-metadata.xml is missing.

The simple solution is to configure the repository to tell it you want to search for artifacts without metadata. See the documentation on how to do that.

@aguibert
Copy link
Author

thanks for the reply @ljacomet, that is a really useful doc page. I found what you are describing in this section:
https://docs.gradle.org/nightly/userguide/upgrading_version_5.html#maven_or_ivy_repositories_are_no_longer_queried_for_artifacts_without_metadata_by_default

But I'm not quite clear on what combination of metadata source need to be added to get the old behavior. Before I had this:

repositories {
    maven {
        url "http://repo.mycompany.com/repo"
    }
}

And according to the doc it sounds like I only need to add the artifact() metadata source like this?

repositories {
    maven {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            artifact()
        }
    }
}

However, now my build fails earlier, so I also added the mavenPom() source too, but I'm not sure if that's correct.

I tried consulting the relevant docs but it just says that metadataSources are an incubating feature in Gradle 5.6, but not what their default values are or what the possible inputs are besides artifact() or mavenPom()

@ljacomet
Copy link
Member

Thanks for the feedback, will look into improving the documentation.
For Gradle < 6.0, the default was:

repositories {
    maven {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            mavenPom()
            artifact()
        }
    }
    ivy {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            ivyDescriptor()
            artifact()
        }
    }
}

and for Gradle >= 6.0 it becomes:

repositories {
    maven {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            mavenPom()
        }
    }
    ivy {
        url "http://repo.mycompany.com/repo"
        metadataSources {
            ivyDescriptor()
        }
    }
}

So to restore pre 6.0 behaviour, you need to copy the old declaration. Note that if your repository never has metadata, you can also simply tell Gradle to look for artifact(), saving you a useless attempt at finding metadata.

@aguibert
Copy link
Author

thanks for the further explanation @ljacomet! I'll go ahead and close this issue since I understand what needs to be changed.

javornikolov added a commit to dbfit/dbfit that referenced this issue Jul 28, 2020
Gradle 6.x has different defaults for ivy repos. This change
allows using dependencies from Amazon S3.

gradle/gradle#10850
javornikolov added a commit to dbfit/dbfit that referenced this issue Aug 25, 2020
Gradle 6.x has different defaults for ivy repos. This change
allows using dependencies from Amazon S3.

gradle/gradle#10850
javornikolov added a commit to dbfit/dbfit that referenced this issue Aug 25, 2020
Gradle 6.x has different defaults for ivy repos. This change
allows using dependencies from Amazon S3.

gradle/gradle#10850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants