Using flatDir like below is one option :
repositories {
flatDir {
dirs 'D:/path/to/local/directory'
}
}
This works. But if there is mavenCentral() or other maven repositories that contain the same JAR, priority will be given to maven repository over flatDir.
Excerpt from Gradle Documentation : https://docs.gradle.org/current/userguide/repository_types.html
Gradle will dynamically generate a module descriptor (without any
dependency information) based on the presence of artifacts. However,
as Gradle prefers to use modules whose descriptor has been created
from real meta-data rather than being generated, flat directory
repositories cannot be used to override artifacts with real meta-data
from other repositories. For example, if Gradle finds only
jmxri-1.2.1.jar in a flat directory repository, but jmxri-1.2.1.pom in
another repository that supports meta-data, it will use the second
repository to provide the module.
So flatDir is not good. We should use local maven repository like mentioned in the second answer. But there are couple of issues with the second answer
- Not portable
- If the artifact is also present in the global repo's, it is unclear from where will it be picked from.
We can solve these issues by using a solution like below :
- Create a folder called libs in the project directory
- Copy your artifacts into this libs directory (if you are using git or any other scm's, make sure to distribute this libs fodler so that others can just
gradle build without any issues)
- Declare a maven repo to your libs directory and call mavenLocal() before listing any other repos. This step is very important to make sure that the jar is picked from your local directory rather than from the other global repositories
repositories {
maven {
url uri("${projectDir}/libs")
}
mavenLocal()
<All your Repos here>
mavenCentral()
}
This way you can be sure that even if the JAR is present in other repo's it will only be picked from your local directory and the solution is also portable.