The Maven Source Plugin is used to create a jar archive of the source files of your project.
Goals:
- source:aggregate aggregates sources for all modules in an aggregator project.
- source:jar is used to bundle the main sources of the project into a jar archive.
- source:test-jar on the other hand, is used to bundle the test sources of the project into a jar archive.
- source:jar-no-fork is similar to jar but does not fork the build lifecycle.
- source:test-jar-no-fork is similar to test-jar but does not fork the build lifecycle.
Configuration:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>attach-sources</id> <phase>verify</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Run the following maven command to generate jar archive of project source files:
mvn install
Output:
[INFO] Installing C:\projects\HelloWorldApplication\target\HelloWorld-1.0-SNAPSHOT-sources.jar to C:\Users\Bijan\.m2\repository\com\qascript\HelloWorld\1.0-SNAPSHOT\HelloWorld-1.0-SNAPSHOT-sources.jar