HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

How to add local .jar file dependency to build.gradle file?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
dependencygradlehowaddfilejarbuildlocal

Problem

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: https://github.com/WalnutiQ/wAlnut/tree/version-2.3.1/referencedLibraries

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

error: package com.google.gson does not exist
import com.google.gson.Gson;


Here is my entire repo: https://github.com/WalnutiQ/wAlnut/tree/version-2.3.1

Solution

If you really need to take that .jar from a local directory,

Add next to your module gradle (Not the app gradle file):

repositories {
   flatDir {
       dirs("libs")
   }
}

dependencies {
   implementation("gson-2.2.4")
}


However, being a standard .jar in an actual maven repository, why don't you try this?

repositories {
   mavenCentral()
}
dependencies {
   implementation("com.google.code.gson:gson:2.2.4")
}

Code Snippets

repositories {
   flatDir {
       dirs("libs")
   }
}


dependencies {
   implementation("gson-2.2.4")
}
repositories {
   mavenCentral()
}
dependencies {
   implementation("com.google.code.gson:gson:2.2.4")
}

Context

Stack Overflow Q#20700053, score: 570

Revisions (0)

No revisions yet.