Open motlin opened 5 months ago
Hi @motlin!
In your project are you running multiple modules/plugins in parallel? There's no threading in the OpenRewrite Maven build plugin, but it looks like the Maven project's resources are getting modified out from under the plugin itself based on the stacktrace.
Hi @shanman190, yes I'm running mvnd
which is pretty similar to running mvn --threads 1C
.
The rewrite plugin is explicitly marked thread-safe: https://github.com/search?q=repo%3Aopenrewrite%2Frewrite-maven-plugin%20threadSafe&type=code
Oh wow, that's quite unfortunate; I must admit I hadn't tried mvnd
with OpenRewrite myself yet (the luxury of having Moderne). Definitely something to fix, or at worst mark the goals as not threadsafe for now. Any suggestions from your side? I'm just catching up and you might have learned more since.
In clicking through the stack trace I'm a bit puzzled why our use of getCompileClasspathElements()
here would lead to a ConcurrentModificationException
.
https://github.com/openrewrite/rewrite-maven-plugin/blob/a482eff78c7bcd86ca5475e9a3f58e090f8e9841/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java#L404-L407
I don't think there's very much we could do differently, seeing how the CCME is triggered on this line in Apache Maven: https://github.com/apache/maven/blob/bc0240f3c744dd6b6ec2920b3cd08dcc295161ae/maven-core/src/main/java/org/apache/maven/project/MavenProject.java#L323
Does the same work for you if you use mvn --threads 1C
instead of mvnd
? I'm wondering if this is something to document, or if we should not mark our goals as thread-safe.
The getArtifacts()
method called in Mavne does indicate that it's lazily populated
All dependencies that this project has, including transitive ones. Contents are lazily populated, so depending on what phases have run dependencies in some scopes won't be included. eg. if only compile phase has run,
Still not sure if that's something we'd have much control over. 🤔
I would think the phases would happen in a serial fashion within each module independently as that particular module works toward the specified goal.
To me this feels like a plugin that is modifying the current module's configuration within a separate thread or an entirely separate plugin in some other module running at the same time is crossing the module boundary. But I don't know for sure.
From the Maven docs, they state that the entirety of Maven proper is all thread safe, but they can make no guarantees on plugins and their specific behavior.
Because of the nature of this as a concurrency problem, I don't run into it frequently and haven't reproduced it with mvn --threads
but they are extremely similar and I assume this is not a problem specific to mvnd
.
It's always possible to make a maven plugin thread-safe but it would be difficult to do it reliably without understanding the problem better. For example, we could add synchronized
blocks around the use of the mavenProject
but it's a total guess at this point.
I think the problem here is OpenRewrite + something else. I'm not sure what the something else part of the equation is though. From an OpenRewrite standpoint, we are reading the dependencies -- as noted by Tim -- while something else is modifying the module's dependencies. Given Maven proper is all thread safe, my only remaining idea is some other plugin of either the current module or a plugin somewhere else in the Maven build is the one that is violating the thread safety here.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a multi module project.
The command I ran was
mvnd install org.openrewrite.maven:rewrite-maven-plugin:dryRun --projects '!liftwizard-example' --activate-profiles 'rewrite-maven-plugin-strict,rewrite-maven-plugin-dryRun' -DskipTests
What is the full stack trace of any errors you encountered?