How to add local .jar file dependency to build.gradle file?
To add a local JAR file dependency to a build.gradle file, you can use the compile fileTree() method and specify the directory where the JAR file is located.
To add a local JAR file dependency to a build.gradle file, you can use the implementation fileTree() method and specify the directory where the JAR file is located. By convention, local dependencies are often placed in a libs/ directory at the root of your project.
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
}This will include all JAR files in the specified directory as dependencies. Note that local JAR dependencies do not automatically resolve transitive dependencies.
You can also specify a single JAR file by using the implementation files() method and specifying the path to the JAR file:
dependencies {
implementation files('libs/my-library.jar')
}Paths should be specified relative to the root directory of the project for better portability.
If you want to exclude certain JAR files from the dependency, you can use the exclude parameter to specify the names of the JAR files that you want to exclude. For example:
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar', exclude: ['jar1.jar', 'jar2.jar'])
}This will include all JAR files in the specified directory except for jar1.jar and jar2.jar.