Compile local JAR files with Gradle

Pete Houston
Dec 3, 2015 · 1 min read

Sometimes, you don’t want to build Java projects with dependencies that need to be downloaded from central repositories, instead having them as JAR files; and many Java libraries really don’t exist in repos. In this case, we need to config Gradle to include all those required JARs during the build, and it is easy.

1. Specifying each JAR filenames

dependencies {
compile files('libs/deps-01.jar', 'libs/deps-02.jar')

This will tell Gradle to include deps-01.jar and deps-02.jar during compilation.

2. Specifying a directory

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')

Everything in libs/ directory with .jar extensions will be included for compiling.

To confirm that all required JARs included in compiling configuration, you can create this helper task,

task listJars << {
configurations.compile.each { File file -> println }

Then run it,

$ gradle -q listJars

That’s it, if you want to learn more about Gradle dependency management, visit Chapter 52.

Have fun :)

Pete Houston

Written by

Code / Design / Love @

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade