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: 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
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
The Gradle dependency cache consists of two storage types located under GRADLE_USER_HOME/caches : A file-based store of downloaded artifacts, including binaries like jars as well as raw downloaded meta-data like POM files and Ivy files.
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 { implementation(files("libs/something_local.jar")) }
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 name: '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' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With