Failure to resolve dependency, but artifact exists

Gradle Version: 2.13
Operating System: MacOS
Is this a regression? Unknown. Different behavior seen in later 2.x releases.

The following dependency fails to resolve in Gradle, with no explanation of the failure, even though it’s found:

apply plugin: 'groovy'

repositories {
    maven { url = 'http://repo.grails.org/grails/repo' }
}

dependencies {
    compile 'org.springframework.uaa:org.springframework.uaa.client:1.0.1.RELEASE'
}

The same dependency resolves with Maven. In later versions of Gradle, rather than failing immediately, the resolve gets stuck in a deep recursion, will sometimes succeed, or stackoverflowing and OOMing when printing the stacktrace.

I was having a brief look at the POM file. It looks to me as if the parent POM has the same coordinates as the POM declared for your dependency.

<project>
    <parent>
        <groupId>org.springframework.uaa</groupId>
        <artifactId>org.springframework.uaa.client</artifactId>
        <version>1.0.1.RELEASE</version>
        <relativePath>../osgi-bundle</relativePath>
    </parent>
    <artifactId>org.springframework.uaa.client</artifactId>
    ...
</project>

Given that the parent POM couldn’t be found under the relative path, Gradle would try to resolve the parent POM with the given GAV and therefore gets caught into an infinite loop. My guess is that Maven has a built-in mechanism to break such loops.

I guess Gradle doesn’t consider the relativePath. Even with the same coordinates, they must be considered different poms by Maven.

Gradle ignores relativePath, it’s only relevent to the maven build for org.springframework.uaa.client when the ../osgi-bundle folder exists on the local file system.

Gradle can only use the GAV to lookup the parent pom when referencing the artifact from a repository.

I’m surprised that maven allows the parent GAV to be the same as the artifact, or any circular dependency in the parent GAV hierarchy. I consider this to be a bug in the pom rather than a bug in gradle. It would be nice if gradle detected the circular dependency and gave a nicer error message

eg:

Detected circular dependency in parent hierarchy org.springframework.uaa:org.springframework.uaa.client:1.0.1.RELEASE → org.springframework.uaa:org.springframework.uaa.client:1.0.1.RELEASE

It seems that http://maven.mit.edu/nexus/content/repositories/GRAILS has fixed the bug here

<parent>
	<groupId>org.springframework.uaa</groupId>
	<artifactId>org.springframework.uaa.osgi.bundle</artifactId>
	<version>1.0.1.RELEASE</version>
	<relativePath>../osgi-bundle</relativePath>
</parent>
<artifactId>org.springframework.uaa.client</artifactId>

I feel that maven is the culprit here, it should have validated the parent’s relativePath against the parent GAV and failed to publish the first pom

Correct, relativePath is not evaluated by Gradle. I opened GRADLE-3485 for the reported issue.

1 Like