Changes

1,662 bytes added ,  16:39, 5 April 2021
add section on flatDir
Line 42: Line 42:  
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Flat Directory Repositories ===
 +
There are occasions where it is needed to temporarily add a dependency on a JAR file that is not present in a Maven repository, such as to add a mod which adds some developer tools during runtime. Gradle allows declaring '''flat directory repositories''', which use a local directory as a simplified repository.<ref>[https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver Gradle User Guide for 6.8.1: ''Flat directory repository'']</ref>
 +
 +
A flat directory repository is declared using a <code>flatDir</code> block within the <code>repositories</code> block, and specifying directories using <code>dirs</code>:
 +
<syntaxhighlight lang="gradle">
 +
repositories {
 +
    flatDir {
 +
        dirs 'lib'
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 +
When a dependency artifact is searched for in a flat directory repository, it will look for the following files in order (<code>''ext''</code> defaults to <code>jar</code>)<ref>[https://github.com/gradle/gradle/blob/v6.8.1/subprojects/core-api/src/main/java/org/gradle/api/artifacts/repositories/FlatDirectoryArtifactRepository.java gradle/gradle; tag v6.8.1; org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository]</ref>:
 +
* <code>''<artifact>''-''<version>''.''<ext>''</code>
 +
* <code>''<artifact>''-''<version>''-''<classifier>''.''<ext>''</code>
 +
* <code>''<artifact>''.''<ext>''</code>
 +
* <code>''<artifact>''-''<classifier>''.''<ext>''</code>
 +
 +
For example, for the dependency <code>:junit:junit:4.8.1</code>, it will first search for <code>junit-4.8.1.jar</code> then <code>junit.jar</code>. The group ID in the dependency descriptor is always ignored.
297

edits