-
Notifications
You must be signed in to change notification settings - Fork 356
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
Apply add dependency correctly, taking aggregating poms into account #4590
Conversation
…endencies when they are used as parent
rewrite-maven/src/main/java/org/openrewrite/maven/AddDependency.java
Outdated
Show resolved
Hide resolved
The naming between Not sure which one to refactor is any |
@@ -115,6 +115,9 @@ public static int getModelVersion() { | |||
@Builder.Default | |||
List<Plugin> pluginManagement = emptyList(); | |||
|
|||
@Builder.Default | |||
List<String> modules = emptyList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid confusion & future changes, perhaps it helps to already adopt the Maven 4 convention of calling these subprojects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, that takes away the ambiguity!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've taken both modules
and subProjects
into account for the RawPom
and named it subProjects
anywhere beyond there
rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java
Outdated
Show resolved
Hide resolved
Perhaps some additions to the |
if (!getResolutionResult().getPom().getSubprojects().isEmpty() | ||
&& (getResolutionResult().getModules().isEmpty() | ||
|| getResolutionResult().getModules().stream().map(MavenResolutionResult::getPom).map(ResolvedPom::getGav).map(ResolvedGroupArtifactVersion::getArtifactId).noneMatch(art -> getResolutionResult().getPom().getSubprojects().contains(art)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bot wants you to place the &&
and ||
on the previous line, in case that wasn't clear before.
Any why the use of Streams API in one of our most used recipes? Does it help to extract the condition into a properly named method such that you can do an early return from a loop there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java
- lines 142-142
rewrite-maven/src/test/java/org/openrewrite/maven/internal/RawPomTest.java
Show resolved
Hide resolved
rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see; I've reworded the conditionals to make it easier to grasp what was added and why; hope you agree! :)
What's changed?
Introduce a mechanism to know which modules an aggregating pom applies to in order to prevent unnecessarily adding dependencies to aggregating poms
Anyone you would like to review specifically?
@timtebeek @sambsnyd
Any additional context
An aggregating pom could be a parent, when it's not there's no point in adding a dependency to it
Checklist