1
votes

I am having a problem resolving a dependency via artifactory using gradle. But I can resolve that dependency using maven, so I'm not sure what I am doing wrong.

The maven build file is:

<dependencies>
  <dependency>
    <groupId>org.geoserver</groupId>
    <artifactId>geoserver</artifactId>
    <version>2.5.1</version>
    <type>war</type>
  </dependency>
</dependencies>

<repositories>
  <repository>
    <name>libs-releases</name>
    <url>http://<artifactory-host>/artifactory/libs-releases</url>
    </repository>
</repositories>

I can confirm that maven will resolve the dependency:

$ mvn dependency:resolve
Downloading: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom
Downloading: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/web/2.5.1/web-2.5.1.pom
Downloading: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.war
[INFO] The following files have been resolved:
[INFO]    org.geoserver:geoserver:war:2.5.1:compile

My gradle build script is:

repositories {
  mavenCentral()
  maven { url 'http://<artifactory-host>/artifactory/libs-releases' }
}

dependencies {
  compile 'org.geoserver:geoserver:2.5.1@war'
}

But gradle will not resolve the dependency:

$ gradle dependencies
:dependencies

compile - Compile classpath for source set 'main'.
\--- org.geoserver:geoserver:2.5.1 FAILED

I've cleaned out the local repository and caches, to ensure that dependencies are resolved. If I turn on debug output I can see that there are HTTP requests for the POM file, but there are no HTTP requests for the WAR file.

[DEBUG] [org.apache.http.impl.conn.DefaultClientConnection] Sending request: HEAD /artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom HTTP/1.1
[DEBUG] [org.apache.http.impl.conn.DefaultClientConnection] Receiving response: HTTP/1.1 200 OK

I can download both the POM and the WAR file directly, so it's not a problem with the artifacts not existing, or proxy issues, or authentication issues:

$ wget http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom
`geoserver-2.5.1.pom' saved [32283/32283]

$ wget http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.war
`geoserver-2.5.1.war' saved [60164745/60164745]  

I can't see what I am doing wrong here. It's probably something simple?

edit #1 I added a dependency on a JAR file in artifactory, which resolved without error. And then I added a dependency on another WAR file in artifactory, which also resolved without error. But for some reason the original geoserver WAR dependency resolves when using maven, but not when using gradle.

edit #2 I see the following warning when using the maven build:

[WARNING] The POM for org.geoserver:geoserver:war:2.5.1 is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for org.geoserver:geoserver:2.5.1
[ERROR] Invalid packaging for parent POM org.geoserver:geoserver:2.5.1, must be "pom" but is "war" @ 
[FATAL] The parents form a cycle: org.geoserver:geoserver:2.5.1 -> org.geoserver:web:2.5.1 -> org.geoserver:geoserver:2.5.1 @ 

Looking at the geoserver 2.5.1 soure code:

  • org.geoserver:geoserver (WAR) has parent org.geoserver:web (POM)
  • org.geoserver:web (POM) has parent org.geoserver:geoserver (WAR)

So there is a cyclic dependency, and the parent of org.geoserver:web has a non-POM packaging.

But maven goes on to download the WAR file despite this 'fatal' error:

Downloaded: http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.war (58755 KB at 8601.2 KB/sec)

Maybe gradle is more strict on this problem?

edit #3 I changed the dependency to exclude transitive dependencies on org.geoserver:geoserver:

dependencies {
  compile('org.geoserver:geoserver:2.5.1@war') {
    transitive = false
  }
  ...

but the dependency still did not resolve when I ran $ gradle dependencies.

There is a stack overflow error when I run a task using this dependency:

$ gradle bundleArtifacts
:bundleArtifacts
FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not resolve org.geoserver:geoserver:2.5.1.
  Required by:
    <my-project>:1.0-SNAPSHOT
> Could not resolve org.geoserver:geoserver:2.5.1.
> Could not parse POM http://<artifactory-host>/artifactory/libs-releases/org/geoserver/geoserver/2.5.1/geoserver-2.5.1.pom
> Could not resolve org.geoserver:web:2.5.1.
> Could not parse POM http://<artifactory-host>/artifactory/libs-releases/org/geoserver/web/2.5.1/web-2.5.1.pom
> Could not resolve org.geoserver:geoserver:2.5.1.
...

This shows that gradle does not get to consider the transitive dependencies, because it cannot parse the POM files, because of the cyclic dependency.

I think the only solution here is to create a separate artifact (such as a ZIP file) that contains the org.geoserver:geoserver:2.5.1 WAR artifact, add a dependency on that ZIP file, and create a task that extracts the contents of that ZIP file to a target directory.

1
The answers here say you cannot add a war as a compile dependency.RaGe
Thanks ... I changed compile to runtime but still failed to resolve ... see my edits.John Q Citizen
Well I really should have said cannot add war as a dependency compile or runtime - atleast that's what the question I linked to says.RaGe
I added a compile dependency on a different WAR artifact (see my edits) and that resolved successfully. I think the problem is that gradle is not as lenient as maven when dealing with POM errors.John Q Citizen

1 Answers

3
votes

It looks like you are using modified pom files which are causing this issue.
The package type of the original org.geoserver:geoserver module is pom and it has no parent. This is the parent pom for the entire geoserver project and should not be used as a dependency.
The org.geoserver:web is also of type pom and serves as the parent for all web related modules.
Looking at the geoserver Artifactory server, I could not find any artifacts named geoserver-x.x.x.war. It seems that someone deployed web archive (war) distribution of geoserver and modified the original pom file of org.geoserver:geoserver so it can be resolved.

If you would like to continue resolving this war, I suggest creating a new dedicated .pom file for it which will not conflict with the geoserver one (using a new groupId/artifactId).