How to depend directly on pom.xml file in Gradle?


(Noel Yap) #1

I have a Scala 2.10 project that depends on Play 2.1. Play 2.1 isn’t published in Maven Central so, at least for now (and since I’ll eventually want to bring up a web service), I’ve unzipped Play into my project and added:

compile files(‘play-2.1.1/repository/local/play/play_2.10/2.1.1/jars/play_2.10.jar’)

But that doesn’t pick up the transitive dependencies. I figured if there’s a way to depend on the pom.xml file, that would fix the problem. Is there a better way?

Thanks, Noel


#2

Your best bet is probably to add a local maven repository with the Play 2.1 module. So in your project, you’ll have a directory that contains the exact file structure that you’d have on Maven Central: eg

repository/local/org/play/play/2.1.1
|- play-2.1.1.pom
|- play-2.1.1.jar

Then include this as a repository definition, and use a regular dependency declaration:

repositories {
     maven { url "${projectDir}/repository/local" }
}
dependencies {
    compile "org.play:play:2.1.1"
}

(Noel Yap) #3

I have the following layout:

$ find play-2.1.1/repository/local/play/play_2.10/2.1.1 -name ‘play*.pom’ -o -name ‘play*.jar’ | xargs ls -l

-rw-r–r--@ 1 nyap 2119906183 4683354 Apr 2 05:25 play-2.1.1/repository/local/play/play_2.10/2.1.1/jars/play_2.10.jar

lrwxr-xr-x 1 nyap 2119906183

18 Jun 29 17:11 play-2.1.1/repository/local/play/play_2.10/2.1.1/play-2.1.1.jar -> jars/play_2.10.jar

lrwxr-xr-x 1 nyap 2119906183

18 Jun 29 17:11 play-2.1.1/repository/local/play/play_2.10/2.1.1/play-2.1.1.pom -> poms/play_2.10.pom

lrwxr-xr-x 1 nyap 2119906183

18 Jun 29 17:20 play-2.1.1/repository/local/play/play_2.10/2.1.1/play_2.10.jar -> jars/play_2.10.jar

lrwxr-xr-x 1 nyap 2119906183

18 Jun 29 17:20 play-2.1.1/repository/local/play/play_2.10/2.1.1/play_2.10.pom -> poms/play_2.10.pom

-rw-r–r--@ 1 nyap 2119906183

6513 Apr 2 05:25 play-2.1.1/repository/local/play/play_2.10/2.1.1/poms/play_2.10.pom

-rw-r–r--@ 1 nyap 2119906183

372324 Apr 2 05:25 play-2.1.1/repository/local/play/play_2.10/2.1.1/srcs/play_2.10-sources.jar

-rw-r–r--@ 1 nyap 2119906183

39690 Apr 2 05:25 play-2.1.1/repository/local/play/play_2.10/2.1.1/srcs/play_2.10-test-sources.jar

And the following in ‘build.gradle’:

repositories {

mavenCentral()

maven {

url “file://${projectDir}/play-2.1.1/repository/local”

} }

repositories {

mavenCentral()

maven {

url “file://${projectDir}/play-2.1.1/repository/local”

}

}

dependencies {

compile ‘play:play_2.10:2.1.1’

}

But Gradle is still not able to find the dependency.

Using hard links (instead of symlinks) doesn’t change the behavior.


(Peter Niederwieser) #4

That’s not a Maven repository layout. It has to be ‘play_2.10-2.1.1.jar’ etc.


(Noel Yap) #5

Since Play ships with Ivy files, too, I tried:

repositories {

mavenCentral()

ivy {

ivyPattern “${projectDir}/play-2.1.1/repository/local//[organisation]/[module]/[revision]/ivys/ivy.xml”

artifactPattern “${projectDir}/play-2.1.1/repository/local/[organisation]/[module]/[revision]/jars/[module].[ext]”

}

}

which works fine. The following doesn’t, though:

repositories {

mavenCentral()

maven {

url “${projectDir}/play-2.1.1/repository/local/[organisation]/[module]/[revision]/poms/[module].pom”

artifactUrls “${projectDir}/play-2.1.1/repository/local/[organisation]/[module]/[revision]/jars/[module].[ext]”

}

}

Using Ivy is good enough for my purposes, but I’m still interested to know how to get it to work with Maven.


(Peter Niederwieser) #6

The following doesn’t, though:

That’s not a valid Maven repo URL.

I’m still interested to know how to get it to work with Maven

I tried to explain this in my previous post.


(Noel Yap) #7

IIUC, Ivy is more flexible than Maven; one’s repo layout must abide by what Maven wants in order to use Maven. Is that correct?


#8

Yes. Maven defines a fixed layout for it’s repositories. The Gradle ‘maven’ repository supports this layout only.