-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MNG-6843] - Parallel build fails due to missing JAR artifacts in compilePath #310
[MNG-6843] - Parallel build fails due to missing JAR artifacts in compilePath #310
Conversation
Each build session will then have its own copy of MavenProject objects and cannot be influenced, for example, get determining compile classpath by other running build threads.
abccf9a
to
ce7be0e
Compare
I wonder if this is the correct fix. This is pretty old code I guess, but I'd like to know why the cloning is required. We've work quite a lot on performance improvements and minimizing the memoryfootprint lately, cloning would have a counter effect. |
The usage of cloned MavenSession objects with shallow copy of MavenProject objects is not thread-safe when it comes to parallel builds because the MavenProjects are being modified from multiple threads. See the https://issues.apache.org/jira/browse/MNG-6843 issue. I don't have big insight in maven code and thus yep, this change fixes something while it might be breaking something different not covered by automated tests. And, most probably, there's another better fix for the issue. I'll try to create a project that simulates the issue deterministically and that can be publicly shared. |
I am also affected by this rather severe bug (see Jira issue MNG-6843). I had a look at the code involved (before this PR patch) and I do not understand why ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor );
List<MavenProject> projectsToResolve =
LifecycleDependencyResolver.getProjects( session.getCurrentProject(), session,
mojoDescriptor.isAggregator() );
for ( MavenProject projectToResolve : projectsToResolve )
{
projectToResolve.setArtifactFilter( artifactFilter );
} The next step after Am I missing something, @rfscholte? |
This will require some good analysis, maybe an annotate/blame on the sourcecode give a hint. |
Three ITs fail when just setting the
|
I need to correct myself: This is the first commit that added the filter handling: d0d3f58 |
This is interesting and a bit frustating: neither this PR nor another approach I implemented locally (with @kodeva Can you verify that this PR fixes your problem? |
@famod I was also going to test the ThreadLocal approach, as it seems as an easiest workaround. I have tried an approach with ThreadLocal around MavenProject.artifactMap,artifactFilter and artifacts. Seemed to work for me, but didn't test it extensively, and it was a few months ago. Have you tried the same? |
@fkalinski This was my approach: famod/maven@master...MNG-6843-parallel-classpath |
I've done actually the same change and it works for me. Before the change, parallel builds were failing around 30% of the time, on the 64-module project I work on. Due to many inter-dependencies, maximum parallelism than can be achieved on the project is around 4. When build fails. it fails fast, as the initial modules that are built are of a small size. After the change applied again today, I haven't seen a failed build, yet. |
As I have checked, the havoc is caused by ensureDependenciesAreResolved setting the artifactFilter to null on all the projects when executing "effective-pom" aggregate mojo. As it's an aggregator, it writes effective pom for each projects. During that it accesses project.getDependencies(), therefore clearing the artifact filters makes some sense, despite that doing that by modifying MavenProject objects is really ugly. Therefore, the problem lies in handling of aggregator mojos, and it's definitely a Maven bug to be fixed. The workaround with ThreadLocals works for me, and it actually should be due to nature of the problem. It would be interesting to see what actaully happens for you, @famod . And specifically in the project I am working on, "maven-help-plugin", with it's "effective-pom" mojo has been configured on the parent project level, thus, clearing the artifact list on execution of all the modules. After moving it to the top pom project parallel build finally works for me! |
@famod - is this still needed please? The approach seems to work by @fkalinski... |
@kodeva No, thanks. I'll revisit this in the next days and I am going to try fkalinski@b38e3c2. |
Unfortunately, fkalinski@b38e3c2 does not fix my problem. |
I am now 100% sure that my problem is a different one. In my case So, sorry for the confusion! I'd just like to add that I found three other Jira tickets that seem to address the same error as MNG-6843 does: |
FYI @kodeva @fkalinski @rfscholte: I've created a new PR with my single |
Superceded by #310 |
Description
The MavenProject objects are shared among all build threads via
MavenSession
- memberorg.apache.maven.execution.MavenSession#projects
.As all the
MavenSession
objects are created by cloning an initialMavenSession
object, I have added cloning of projects into theMavenSession#clone
method.With this change each build has its own copy of
MavenProject
objects and this way unintention changes of the objects from different build threads is avoided.Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MNG-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
MNG-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.