Could you give me a detail explanation about the difference between jar and jar-no-fork goal?
I see it from official site, but I can not get a clear idea for this.
Full name: org.apache.maven.plugins:maven-source-plugin:3.2.1:jar-no-fork. Description: This goal bundles all the sources into a jar archive. This goal functions the same as the jar goal but does not fork the build and is suitable for attaching to the build lifecycle.
The source plugin can be used to create a jar file of the project sources from the command line or by binding the goal to the project's build lifecycle. To generate the jar from the command line, use the following command: mvn source:jar.
The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.
That sources jar is a jar that contains only the source code (the . java files) corresponding to the compiled artifact. It is useful to add it as a source attachment in your IDE, to publish the sources, etc. As it only contains sources, not compiled classes (. class files), it is of no use as a library dependency.
My interpretation: the jar
goal is meant to be run from the command line (mvn source:jar
), the jar-no-fork
is meant to be bound to the lifecycle.
If you look at the docs for the jar
goal the key phrase is "Invokes the execution of the lifecycle phase generate-sources prior to executing itself." If you configure your POM to run the source:jar
goal as part of the lifecycle, Maven will re-run all of the goals bound to generate-sources
and its predecessors. If you have many plugin goals bound to the validate or initialize phases all of those will run twice, lengthening the time of your build.
In contrast, jar-no-fork
is what you attach to the build lifecycle because it expects to be bound to a phase somewhere after generate-sources
and will not run the bound goals again.
I have verified this behavior by running Maven 3 with -X
and reviewing the plugin executions that run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With