How to add local .jar file dependency to build.gradle file?
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'
}
How to import local *jar per gradle?
I always prefer a simple approach like:
Copy your JAR file to your module
libs
folder.Add the dependency in the
build.gradle
file
In build.gradle
:
dependencies {
// Dependency on local binaries
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Alternatively, you can specify individual files as follows:
//implementation files('libs/myJar.jar', 'libs/bar.jar')
//..
}
It is not related to a particular procedure to follow, it works with different IDE (also in a CI environment), just all the code and the jars file are in the git repo and the build.gradle script is enough to build the project.
How do you add local .jar file dependency to build.gradle.kt file?
If you are looking for the equivalent of
implementation fileTree(dir: 'libs', include: ['*.jar'])
that would be:
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
Add custom *.jar file into build.gradle project dependencies and set up the classpath
Your dependency in base:dynamic-validation
won't work with a declaration like this: it's a relative path to the current project, not the root.
To be able to use file dependency, just add this code to the repositories list in the main build.gradle:
repositories {
flatDir {
dirs "$rootProject.projectDir/externalLib"
}
...
}
https://riptutorial.com/gradle/example/8349/add-a-local-jar-file-dependency
Gradle dependencies: compile using local jar vs compile from maven repository?
The difference is the Project Object Model (POM), its presence or absence. The POM file pom.xml
contains the dependencies of a particular module and is usually deployed with the project artifacts to a Maven repository.
When you say compile files()
, Gradle has only access to the artifact. Since the POM is absent, dependency information is not available and the build is likely to fail. In contrast, when declaring dependencies resolved from a proper repository, Gradle fetches the POM before downloading the actual artifact and its dependencies and transitive dependencies.
You can achieve the same effect with local jars by
Downloading all dependencies and transitive dependencies (and so on) to a local folder and reference them accordingly
compile files('/path/to/jar/file/*.jar')
Use flat directory repositories
- Create a uber/fat/shaded/shadow of the particular library so that it includes all dependencies in a single
jar
file.
Related Topics
Maven: Add a Dependency to a Jar by Relative Path
Difference Between String Object and String Literal
Do We Have Any Generic Function to Check If Page Has Completely Loaded in Selenium
How to Address Unchecked Cast Warnings
In Java Streams Is Peek Really Only For Debugging
How Are Ssl Certificate Server Names Resolved/How to Add Alternative Names Using Keytool
What Are Static Factory Methods
What Is the Ellipsis (...) For in This Method Signature
Equals VS Arrays.Equals in Java
Java Runtime.Getruntime(): Getting Output from Executing a Command Line Program
How to Use Different Certificates on Specific Connections
How to Implement Rest Token-Based Authentication With Jax-Rs and Jersey
Scanning Java Annotations At Runtime
What's Causing My Java.Net.Socketexception: Connection Reset