Tag Archives: 3rd party jar

[repost ]Gradle: Make a 3rd party jar available to local gradle repository

original:http://stackoverflow.com/questions/2572811/gradle-make-a-3rd-party-jar-available-to-local-gradle-repository

question:

currently, I’m testing Gradle as an alternative to Maven. In my projects, there are some 3rd party jars, which aren’t available in any (Maven) repositories. My problem is now, how could I manage it to install these jars into my local .gradle repository. (If it’s possible, I don’t want to use the local Maven repository, because Gradle should run independently.) At the moment, I get a lot of exceptions because of missing jars. In Maven, it’s quite simple by running the install command. However, my Google search for something similar to the Maven install command wasn’t successful. Has anybody an idea?

 

answer1 :

you can include your file system JAR dependencies as:

dependencies {
    runtime files('libs/a.jar', 'libs/b.jar')
    runtime fileTree(dir: 'libs', include: '*.jar')
}

you may change runtime for compile/testCompile/etc..

 

answer2:

A more comprehensive answer was given on a mailing list by Adam Murdoch athttp://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle-repository-td1431953.html

As of April 2010 there was no simple way to add a new jarfile to your ~/.gradle repository. Currently researching whether this has changed.

answer 3:

Used option (1) out of Adam Murdoch post (already linked above:http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle-repository-td1431953.html) with gradle-1.3 and it works just nicely!

Here his comment:

  1. Copy the jars to a local directory and use a flatDir() repository to use them out of there. For example, you might copy them to $projectDir/lib and in your build file do:

repositories { flatDir(dirs: ‘lib’) }

The files in the lib directory must follow the naming scheme: name-version-classifier.extension, where version and classifier are optional. So, for example you might call them groovy-1.7.0.jar or even groovy.jar

Then, you just declare the dependencies as normal:

dependencies { compile ‘groovy:groovy:1.7.0’ }

There’s a little more detail one flatDir() repository at: http://gradle.org/0.9-preview-1/docs/userguide/dependency_management.html#sec:flat_dir_resolver

  1. Similar to the above, but using an ivy resolver instead of flatDir(). This is pretty much the same as the above, but allows a lot more options as far as naming and locations go.

There’s some detail at: http://gradle.org/0.9-preview-1/docs/userguide/dependency_management.html#sub:more_about_ivy_resolvers

  1. Don’t bother with declaring the dependencies. Just copy the jars to a local directory somewhere and add a file dependency. For example, if the jars are in $projectDir/lib:

dependencies { compile fileTree(‘lib’) // this includes all the files under ‘lib’ in the compile classpath }

More details at: http://gradle.org/0.9-preview-1/docs/userguide/dependency_management.html#N12EAD

  1. Use maven install to install the dependencies into your local maven cache, and the use the maven cache as a repository:

repositories { mavenRepo(urls: new File(System.properties[‘user.home’], ‘.m2/repository’).toURI().toURL()) }