Get source JARs from Maven repository
At a glance, here's how you retrieve source JARs and Javadocs for your dependencies with Maven:
mvn dependency:resolve -Dclassifier=sources
mvn dependency:resolve -Dclassifier=javadoc
These commands fetch the respective files and store them in your local Maven cache for easy access. However, note that not all dependencies may provide sources or Javadocs.
Tailoring your dependency management
Specific dependencies handling
You may need to handle your dependencies selectively. Maybe you want to include certain artifacts and exclude others. Here's how to do that:
Here your includeArtifactIds
and excludeGroupIds
are personal to your project. Just replace the placeholders and you're good to go.
Repository search engines
Sometimes your artifacts are playing hide and seek, and aren't found easily. Use repository search engines like Maven Central Repository Search or Sonatype Nexus to find all your hide-and-seek champion artifacts.
Your source JAR packaging
Are you about to embark on your open-source journey? Here is the magic spell to package your source JARs using maven-source-plugin
:
Packaging your source JAR along with your project's binaries helps the dev community to gaze into your brilliant mind.
Visual representation
Getting source JARs could be seen as a treasure hunt:
The Maven Repository (🏛️): It houses countless artifacts (groupId:artifactId:version).
Our Quest (🔍): To find the hidden treasure (source JARs).
Steps to winning your Quest:
IDE integrations
IntelliJ IDEA
IntelliJ IDEA users can awesomely get the sources right in their IDE with this sweet command:
Your sources are automatically stitched into the fabric of IntelliJ, boosting your productivity.
Eclipse
For Eclipse users, this command will get you going:
An additional tweak in your POM file to embed the maven-eclipse-plugin
will ensure a continuous supply of source files:
Was this article helpful?