How to use a jar from a SourceForge project as a dependency in a project?

(Stig Kleppe-Jørgensen) #1

How can I add an URL-based repository in a plugin so I can download a dependency from a SourceForge project?

I had something like this:

project.repositories.add(new CommonsHttpClientResolver(null, null)) {
    name = 'SourceForge'
    addArtifactPattern '[organization]/files/[organization]/[organization]-[revision]/[module]-[revision].[ext]/download'

But in 1.0-milestone-7 this internal CommonsHttpClientResolver class was removed. Its replacement, IvyResolver, is not as easy to use, as it needs some setup which I don’t know how to do.

I also tried Ivy’s URLResolver, but it seems this does not handle redirects (HTTP 302) at all.

(Benjamin Muschko) #2

Something like this should work:

repositories {
    add(new org.apache.ivy.plugins.resolver.URLResolver()) {
        name = 'SourceForge'
        addArtifactPattern '[organization]/files/[organization]/[organization]-[revision]/[module]-[revision].[ext]/download'

(Stig Kleppe-Jørgensen) #3

As I said, I already tried Ivy’s resolver, but it did not handle redirects.

(Benjamin Muschko) #4

Sorry, must have missed that when reading the description.

(Benjamin Muschko) #5

I am not quite sure if this pattern applies to all SourceForge projects but here’s one example for a JAR file that I was able to download. I adapted to the link provided on the download page where it says “direct link”.

apply plugin: 'java'
  repositories {
    add(new org.apache.ivy.plugins.resolver.URLResolver()) {
        name = 'SourceForge'
        addArtifactPattern '[organization]/[module]-[revision].[ext]?r=&ts=&use_mirror=voxel'
  dependencies {
    compile 'h2jars:h2small:1.2.128@jar'


Have you tried an ‘ivy’ repository with the appropriate pattern?

Something like this may work:

repositories {
    ivy {
        artifactPattern '[organization]/files/[organization]/[organization]-[revision]/[module]-[revision].[ext]/download'

(Stig Kleppe-Jørgensen) #7

Yes, I tried that too…it does not work because it tries to download the Ivy metadata (ivy.xml or whatever it is called) before downloading the jar

(Stig Kleppe-Jørgensen) #8

Yeah, this works…the only thing being that I have to choose a mirror

(Stig Kleppe-Jørgensen) #9

As I edited the entry several times, you might have read it before I added that part :slight_smile:


The problem with using URLResolver directly is that you miss out on a lot of Gradle goodness. While caching should work in general, you no longer benefit from sha1 matching of artifacts. So you’ll need to re-download the artifacts whenever you run with “–refresh dependencies” (M8) and often when you upgrade Gradle. Also, changing artifacts will be re-downloaded every resolve. So I’d like to help find a solution that doesn’t involve using an ivy resolver directly.


I see, the issue is that sourceforge is not returning a 404 when you request an unknown artifact. If you use the same (mirror-specific) url quoted by Benjamin Muschko above, it works.

repositories {
    ivy {
        artifactPattern '[organization]/[module]-[revision].[ext]?r=&ts=&use_mirror=voxel'

Soon we are planning to add the ability to configure the meta-data format you want for a repository: maven, ivy, jarfile. This will help clarify the behaviour and should provide a way to get the regular sourceforge “*/download” url working.

(Tim Harsch) #12

Any idea when? I just decided to move our build from Maven to Gradle, predicated on the ability to create an uber jar (with Stig’s plugin). I’ll try your work around, but just curious as to when the ability you mention will be in place…

(Stig Kleppe-Jørgensen) #13

I have released a new version of the gradle-executable-jar-plugin which uses the regular Ivy resolver with a hard coded url to a specific mirror.

Cudos goes to Benjamin and Daz that got me on the right track :slight_smile:

PS. the release is pushed to Sonatype’s Maven repo that syncs every 2 hours to Maven Central, so it might take some time yet before it is available.

(Stig Kleppe-Jørgensen) #14

Thanks Daz, it seems the url must be on this format, though:[organization]/[organization]/[organization]-[revision]/[module]-[revision].[ext]

organization is repeated and an extra level with org-rev must be there too. This is only tested with the 1.0-milestone-8 snapshot, though.

(João Paulo Freire) #15

I was trying to download zip file from
    compile 'firebirdsql:jca-jdbc-driver:jaybird-jdk17:2.2.2@zip'

without success.

What I am trying to achive: unzip .dll or .so file direcly from sourceforge based on my jdk settings


What does your repository declaration look like?

(João Paulo Freire) #17

among lots of others, I think this was the last one…

ivy {
        artifactPattern '[organization]/files/[organization]-[module]/[revision].zip/download'
                        //link to download

(Stig Kleppe-Jørgensen) #18

You need to use a specific mirror url, like this:[organization]/[organization]/[organization]-[revision]/[module]-[revision].[ext]

And yes, the organization must be duplicated. Now then just replace mirror-id with the id of a mirror and you are good to go.