Gradle – Flat Repo (flatdir)

What the heck is a Flat Dir repository in Gradle?  Well, its basically a directory(s) that contain a set of files that can be used to resolve dependencies.

  • Note, Gradle will assume  no transitive dependencies with this type of repo.

A good use of this repository type may be within a company that does not have its own internal repository and does not allow builds to resolve dependencies externally at build time.

So their Gradle build file might look something like this if they need to pull in specific jar versions from the lib folder at compile time.  Gradle will use the jar name from the lib folder for resolution.

repositories {
   flatdir { dir 'lib' }
}

dependencies {
   compile group: 'junit', name: 'junit', version: '4.12'
   ...
   ...
}

Now if they have a lib folder with jar files managed uniquely and they want to include all of them at compile time, then the Gradle build script might look like this.

dependencies {
   compile fileTree(include: ['*.jar'], dir: 'lib')
}

 

gradle