Download source JARs (sources.jar) from a Maven repository
Codemia Knowledge Hub ·
Run mvn dependency:sources to download the source JARs for all of your project's dependencies into the local repository. For a single library, download its -sources.jar file from the repository's web interface, or let your IDE fetch sources automatically.
What a source JAR contains
A source JAR mirrors a normal binary JAR but contains the .java source files that correspond to its class files. Keeping source and binaries in separate JARs keeps production artifacts lean while letting developers download the source when they need it.
Source JARs let you step through library code while debugging, learn from well-designed code, and read the comments and annotations that often serve as the best documentation.
Option 1: the Maven Dependency Plugin
The Maven Dependency Plugin's dependency:sources goal downloads the source code of all your project dependencies:
Maven fetches the source JARs for every dependency listed in your pom.xml and stores them in your local repository, which is especially useful for large projects with many dependencies, since one command covers all of them.
Option 2: manual download from the repository website
Repositories such as Maven Central or JFrog have web interfaces. Open the artifact's page and download the file labeled -sources.jar. This is straightforward and works for a one-off lookup, but it becomes impractical when you need sources for many dependencies.
Option 3: let the IDE download sources
IntelliJ IDEA and Eclipse can download source JARs automatically, usually configured in the IDE's Maven settings, which suits everyday development. In IntelliJ, go to File > Settings > Build, Execution, Deployment > Build Tools > Maven > Downloading and enable "Download sources automatically."
Practical tips
- Download only what you need to keep storage use down.
- Check licenses to make sure your use of the source code complies.
- Use trusted, official repositories to avoid malicious code.
The three approaches compare like this:
| Method | Ease of Use | Ideal Usage Scenario |
| Maven Dependency Plugin | High | Multiple dependencies; batch updates |
| Manual Download | Medium | Single, isolated cases |
| Integrated Development Environment | High | Continuous everyday development |
Related reading
- Get specific ArrayList item
- Get spinner selected items text?
- Get spring application environment in thymeleaf
- Get the length of a String
- Get the creation date of a stash
- Get the current git hash in a Python script
- Get the POST request body from HttpServletRequest
- Get type of a generic parameter in Java with reflection
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.