Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Maven source plugin jar and jar-no-fork goal?

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.

like image 923
Tim Avatar asked May 12 '12 21:05

Tim


People also ask

What is jar no fork?

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.

What is the use of maven source plugin?

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.

What is maven sources 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.

What is source jar?

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.


1 Answers

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.

like image 54
user944849 Avatar answered Sep 30 '22 14:09

user944849