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

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 'https://sourceforge.net/projects/[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.

Something like this should work:

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

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

Sorry, must have missed that when reading the description.

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 'http://downloads.sourceforge.net/project/[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 'https://sourceforge.net/projects/[organization]/files/[organization]/[organization]-[revision]/[module]-[revision].[ext]/download'
    }
}

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

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

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 'http://downloads.sourceforge.net/project/[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.

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…

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.

Thanks Daz, it seems the url must be on this format, though:

http://mirror-id.dl.sourceforge.net/project/[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.

I was trying to download zip file from

http://sourceforge.net/projects/firebird/files/firebird-jca-jdbc-driver/2.2.2-release-jdk17/Jaybird-2.2.2JDK_1.7.zip/download
    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?

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

ivy {
        artifactPattern 'https://sourceforge.net/projects/[organization]/files/[organization]-[module]/[revision].zip/download'
                        //link to download
                        //http://sourceforge.net/projects/firebird/files/firebird-jca-jdbc-driver/2.2.2-release-jdk17/Jaybird-2.2.2JDK_1.7.zip/download
    }
    mavenCentral()

You need to use a specific mirror url, like this:

http://mirror-id.dl.sourceforge.net/project/[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.