Java – How to add local .jar file dependency to build.gradle file


So I have tried to add my local .jar file dependency to my build.gradle file:

apply plugin: 'java'

sourceSets {
    main {
        java {
            srcDir 'src/model'

dependencies {
    runtime files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')
    runtime fileTree(dir: 'libs', include: '*.jar')

And you can see that I added the .jar files into the referencedLibraries folder here:

But the problem is that when I run the command: gradle build on the command line I get the following error:

error: package does not exist

Here is my entire repo:

Best Solution

According to the documentation, use a relative path for a local jar dependency as follows.

Groovy syntax:

dependencies {
    implementation files('libs/something_local.jar')

Kotlin syntax:

dependencies {