Resolving dependencies from parent project


(awouda) #1

Hi,

I’m converting a set of maven projects that eventually should result in an EAR to a Gradle build. So far so good. But now I encounter an issue I cannot seem to figure out myself:

One of the projects had a dependency to hibernate-spatial-mysql (in the original pom). This pom has eventually a parent called hibernate- spatial-maven (here: http://bit.ly/wxu2Jl ) that has amongst others a dependency to com.vividsolutions:jts:1.10.

This vividsolutions jar is used in the project at hand.

Now when I build the original project with maven, things go fine. But my gradle build fails, it cannot find the com.vividsolutions jar.

I reproduced the problem in a simple setup. First the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <modelVersion>4.0.0</modelVersion>
 <groupId>wouda.test</groupId>
 <artifactId>spatial-ding</artifactId>
 <version>0.1</version>
    <dependencies>
  <dependency>
   <groupId>org.hibernatespatial</groupId>
   <artifactId>hibernate-spatial-mysql</artifactId>
   <version>1.0</version>
   <scope>provided</scope>
  </dependency>
  </dependencies>
 <repositories>
    <repository>
   <id>Hibernate Spatial repo</id>
   <url>http://www.hibernatespatial.org/repository</url>
  </repository>
      </repositories>
</project>

The same goal but with maven:

apply plugin: 'java'
    dependencies {
 compile group: 'org.hibernatespatial', name: 'hibernate-spatial-mysql', version: '1.0'
               }
  repositories {
 maven {
  url "http://download.java.net/maven/2"
          artifactUrls "http://www.hibernatespatial.org/repository"
 }
}

Now when you run “mvn dependency:tree” is shows something like:

[INFO] \- org.hibernatespatial:hibernate-spatial-mysql:jar:1.0:provided
[INFO]
  +- org.hibernatespatial:hibernate-spatial:jar:1.0:provided
[INFO]
  +- org.hibernate:hibernate-core:jar:3.3.2.GA:provided
[INFO]
  |
+- antlr:antlr:jar:2.7.6:provided
[INFO]
  |
+- commons-collections:commons-collections:jar:3.1:provided
[INFO]
  |
+- dom4j:dom4j:jar:1.6.1:provided
[INFO]
  |
|
\- xml-apis:xml-apis:jar:1.0.b2:provided
[INFO]
  |
+- javax.transaction:jta:jar:1.1:provided
[INFO]
  |
\- org.slf4j:slf4j-api:jar:1.5.8:provided
[INFO]
  +- com.vividsolutions:jts:jar:1.10:provided
                             <-- This is wat we need

But when I run gradle dependencies I get:

compile - Classpath for compiling the main sources.
\--- org.hibernatespatial:hibernate-spatial-mysql:1.0 [default]

That’s it. The ‘upwards’ dependencies that are defined in the parent pom (hibernate-spatial-maven) are not put on the compile time classpath.

I’ve tried things with ResolutionStrategy but that does not work.

Also when I remove the url “http://download.java.net/maven/2” in the repositories block, I get an error that It cannot find vividsolutions.

So it seems, the gradle build is working fine in the sense that it fetches all the dependencies of the parent pom, however it is used during compile time?

How can I get these parent dependencies on the classpath?

tia,

Alex


(Szczepan Faber) #2

Hey,

Given your build file, here’s what’s happening:

  1. Gradle looks for metadata (in maven’s case, the poms) here: http://download.java.net/maven/2 2. Gradle doesn’t find the metadata (above repo does not contain any metadata for hibernatespatial) 3. Gradle is about to fail the build but… it discovers that you have supplied the artifact url. So, gradle tries to grab the jar ignoring the pom.xml. 4. Gradle finds the jar under the http://www.hibernatespatial.org/repository and fetches it. However, the jar does not contain any dependency information (it’s just the jar).

Solution: 1. Dont use artifactUrl. Configure your repositories directly to http://www.hibernatespatial.org/repository. Make sure to add other missing repositories so that all transitive dependencies are resolved fine. Something like that:

repositories {
    maven {
        url "http://www.hibernatespatial.org/repository"
    }
    mavenCentral()
    ...
}

Hope that helps :slight_smile:


(awouda) #3

Thanks.

Your answer led me to the solution. It seems only the vividsolutions package was needed. This is grabbed from a total other place than the repo defined in the parent-pom of the hibernate-spatial-mysql package.

This is now the correct build.gradle of the concerning sub-project.

version = '2.0.1'
  dependencies {
         compile group: 'com.vividsolutions', name: 'jts', version: '1.10'
 compile project(':DomainModel_COMMON'), project(':GEO_Conversion'),
project(':eCALLXMLEXCHANGE')
   }
  repositories {
 maven { url "http://download.osgeo.org/webdav/geotools" }
}

Still wonder how maven can find the osgeo.org location though…

But for now I can continue, thanks.

Alex