user48267
user48267

Reputation: 51

How to use gradle to link a jar in lib?

The project looks like:

Project

/src /a.java

/lib /B.jar

/bin

(a.java use some class in B.jar)

How to link B.jar and build the project by gradle?

Upvotes: 4

Views: 1575

Answers (1)

Benjamin Muschko
Benjamin Muschko

Reputation: 33456

First of all create a new build script named build.gradle on the root level of your project. You will need to apply the Java plugin and set your source directory to src as it doesn't use the default project layout. We also assign your JAR file dependency to the compile configuration. Running gradle build will compile your code, run tests (which you don't have) and assemble your module's artifact.

apply plugin: 'java'

sourceSets {
    main {
        java {
            srcDirs = ['src']
        }
    }
}

dependencies {
    compile fileTree(dir: 'lib', include: 'B.jar') 
}

Upvotes: 8

Related Questions