Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use gradle to link a jar in lib?

Tags:

java

gradle

jar

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?

like image 288
user48267 Avatar asked Feb 20 '23 03:02

user48267


1 Answers

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') 
}
like image 196
Benjamin Muschko Avatar answered Mar 05 '23 18:03

Benjamin Muschko