In Gradle, adding dependencies from local JAR files requires specific configurations within the build.gradle file. An attempt to include local JARs using the following code block may lead to errors:
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') }
Solution:
To successfully include local JAR dependencies, Gradle recommends using a relative path instead. The corrected code block for Groovy syntax is:
dependencies { implementation files('libs/something_local.jar') }
For Kotlin syntax, the code would be:
dependencies { implementation(files("libs/something_local.jar")) }
By following this approach, Gradle can locate and include the specified JAR dependencies during the build process. This resolves the issue where packages from the JAR files are not recognized, as seen in the error message:
error: package com.google.gson does not exist import com.google.gson.Gson;
The above is the detailed content of How to Properly Include Local JAR Dependencies in Gradle?. For more information, please follow other related articles on the PHP Chinese website!