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

1

41

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.

Stafani answered 12/5, 2012 at 21:31 Comment(3)
One forks a thread, one doesn't.Manvil
What do you mean fork a thread?Stafani
The jar goal causes a warning in Jenkins, see issues.jenkins.io/browse/…Tieback
G
61

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.

Grampositive answered 12/5, 2012 at 22:55 Comment(4)
The default phase and the minimum version are both described in the attributes section of the jar-no-fork documentation.Grampositive
This is my understanding as well, but then the strange thing is that the super POM of Maven 3.0.4 uses the jar goal, not the jar-no-fork goal in the release-profile. Any idea why?Isochronous
No idea. Perhaps the jar-no-fork goal was added to the plugin after Maven 3.0.4 was released. You'd have to check the release notes for both.Grampositive
Using the goal 'jar-no-fork' is essential for use with the maven-release-plugin. If you use the goal 'jar', the build will fail with an error saying 'Presumably you have configured maven-source-plugin to execute twice in your build.' This happens, I guess, because maven checks for the sources.jar and tries to generate it, while it is actually already being built in another thread.Bontebok

© 2022 - 2024 — McMap. All rights reserved.