Dependency is being resolved by Maven but not Gradle

Hi there,
As the title suggest I have a dependency that is published on maven central. The dependency is org.apache.gossip:gossip:0.1.2-incubating . When i try to build the project It is not resolved by the Gradle. However the jar has been resolved by the maven and is located in my .m2 folder. Therefore I can use maven to build. I managed to fix this by adding mavenLocal() in my repositories but in remote server such as Travis it can’t be built.
My build.gradle file looks as following:

repositories {

    // maven { url "https://repo.maven.apache.org/maven2" }
    mavenCentral()
    //mavenLocal()
}
dependencies {
    compile group: 'org.apache.gossip', name: 'gossip', version: '0.1.2-incubating'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2'
    compile group: 'com.google.guava', name: 'guava', version: '23.0'
    compile group: 'org.yaml', name: 'snakeyaml', version: '1.18'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

What I tried:

  • Clean caches
  • Kill daemon
  • Deleted gradle folders both on ~ and in project root
  • Removed .m2
  • Try Gradle 2.7 and 4.1

But it won’t build both in my machine and Travis.
Output of build:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.apache.gossip:gossip:0.1.2-incubating.
  Required by:
      project :
   > Could not resolve org.apache.gossip:gossip:0.1.2-incubating.
      > Could not parse POM https://repo.maven.apache.org/maven2/org/apache/gossip/gossip/0.1.2-incubating/gossip-0.1.2-incubating.pom
         > Could not find org.apache:apache:RELEASE.
           Searched in the following locations:
               https://repo.maven.apache.org/maven2/org/apache/apache/RELEASE/apache-RELEASE.pom
               https://repo.maven.apache.org/maven2/org/apache/apache/RELEASE/apache-RELEASE.jar

Could you please help me to solve this problem? Thanks!

This is because this POM is referencing version RELEASE of it’s parent POM. Support for these dynamic version keywords was dropped years ago in Maven 3. So basically Gradle is not going to be able to parse the POM here. You can get around this by grabbing the JAR artifact directly via compile 'org.apache.gossip:gossip:0.1.2-incubating@jar' but this means transitive dependencies will need to be declared explicitly.

1 Like

Thank you so much! But I still get the same error and output even though I add the dependency the way you describe. I don’t really want to distribute jar manually with my source code. Is there any way to make gradle resolve it? Thanks again!

I think gradle can handle retrieving a pom from one repository and a jar from another and it will use the repository ordering from the build.gradle.

You might be able to use a file based repository under source control which has tweaked poms for the “broken” artifacts without needing the jars under source control. Make sure you declare the tweaked repository first

I think this is a viable option since I can’t update the remote POM. Thanks for helping out!

I’m not suggesting that you change the remote pom. I’m suggesting that you take a copy of the remote pom to a local folder and fix the local version. Then you configure two repositories in your build.gradle.

repositories {
   maven {
      // fixed pom goes gere
      url uri(file('localFolder')) 
   } 
   maven {
      // broken pom and jars here
      url 'http://remote/repo' 
   } 
} 
1 Like

I know you don’t mean changing remote POM. But thank you so much for the code snippet.

I know you don’t mean changing remote POM

Whoops! Misread your response