Local JAR Dependency Integration in Gradle
Adding local JAR file dependencies to a build.gradle file can enhance project functionality. To address this requirement, Gradle provides a standardized approach.
Issue Description
An attempt to include local JAR files in build.gradle using the following configuration:
runtime files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar') runtime fileTree(dir: 'libs', include: '*.jar')
However, this approach resulted in an error when running gradle build, indicating a missing package: package com.google.gson does not exist.
Solution
As mentioned in the Gradle documentation, local JAR dependencies should be referenced using a relative path. The corrected dependency configuration is:
dependencies { implementation files('libs/something_local.jar') }
Kotlin Syntax
For projects using Kotlin syntax, the dependency configuration can be written as:
dependencies { implementation(files("libs/something_local.jar")) }
Note
Ensure that the JAR files are placed in the correct directory relative to the build.gradle file. In this case, the JAR files would be located in the libs directory.
By following these instructions, you can successfully integrate local JAR file dependencies into your Gradle-based project.
The above is the detailed content of How to Correctly Add Local JAR Dependencies in Gradle?. For more information, please follow other related articles on the PHP Chinese website!