Reputation: 13238
Most of the IDEs nowadays supports downloading the sources for added dependencies and it quite work well when we want to look the Class/Interface/Method definitions into source code.
My question is around how IDEs figure out the sources (artifacts containing source code) online and automatically downloads them.
Lets say I want to publish my library as open source and make it the part of maven central repo, what do I need to do in order to support this Download Sources functionality?
Upvotes: 1
Views: 52
Reputation: 62466
In the Maven ecosystem, source files are commonly bundled into a specific package with the maven-source-plugin:
The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.
By convention, the name of the source package ends with -sources.jar
such as hsqldb-1.8.0.7-sources.jar
. The sources
part of the name is known, in Maven, as the classifier:
The classifier distinguishes artifacts that were built from the same POM but differ in content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.
[...] use case for classifiers is to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.
Knowing this convention, it's easy for an IDE to retrieve the source files of dependencies from Maven central or from other configured Maven repositories.
Upvotes: 1