Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add library to gradle build

I'm trying to add org.apache.commons.lang3 to my build. I've downloaded the library which is directory containing jar files.

My group is using gradle to build the project, and I know just enough to maybe ask the right question. So what I think the build is doing is

  1. copying a bunch of .bnds to the build directory
  2. compiles the java we have in src/main/java (via source sourceSets.main.java.srcDirs?)

I would like to add the lang3 library, but I'm not sure how to go about doing that. Can I just dump it into src/main/java? Or do I have to tell gradle about it?

This is what I think is relevant from the current build.gradle

ext.releaseDir = "${buildDir}/release/${tpVersion.getProgramName()}"
ext.bundlesDir = "${releaseDir}/nucleus/bin/nucleus_java/bundles/"

dependencies {
   compile fileTree(dir: bundlesDir, include: '*.jar')

bnd {
   source sourceSets.main.java.srcDirs
   include '**/*.bnd'
like image 952
itchmyback Avatar asked Jan 10 '14 06:01

itchmyback


1 Answers

You could declare it as a dependency, if it exists in any remote repository. That's the way I would do it.

But if you want to use the local file, do not put it in src/main. Use an extra folder called lib or similar on the same directory level as src or you build script.

Then you can add the local dependency to the build.gradle as in this sample:

repositories {
    //central maven repo
    mavenCentral()
}

dependencies {
    //local file
    compile files('libs/toxiclibscore.jar')

    //dependencies from a remote repository
    compile 'java3d:vecmath:1.3.1', 'commons-lang:commons-lang:2.6'
}
like image 165
Spindizzy Avatar answered Oct 11 '22 12:10

Spindizzy