gnodet-bot commented on code in PR #29353:
URL: https://github.com/apache/camel/pull/29353#discussion_r4496517525
##########
dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/ExportHelper.java:
##########
@@ -216,6 +216,31 @@ public static String exportPackageName(String groupId,
String artifactId, String
return sb.toString();
}
+ /**
+ * Keeps a single dependency per groupId:artifactId in the dependencies of
a pom.xml, which may name an artifact
+ * only once (Maven 3.10 onwards fails the build of a project that names
one twice). Two dependencies with other
+ * coordinates become the same artifact through the mapping of a runtime:
{@code org.apache.camel:camel-console} and
+ * {@code org.apache.camel.quarkus:camel-quarkus-console} are the same
artifact of the Quarkus runtime. The first is
+ * kept, in its position, except that a dependency with a version wins
over one without: the mapping of a runtime
+ * leaves the version of its own artifacts to the BOM, so the coordinates
a user gave with a version survive it.
+ */
+ public static void removeDuplicateArtifacts(List<MavenGav> gavs) {
+ Map<String, MavenGav> kept = new LinkedHashMap<>();
+ for (MavenGav gav : gavs) {
+ String ga = gav.getGroupId() + ":" + gav.getArtifactId();
+ MavenGav existing = kept.get(ga);
+ if (existing == null || !hasVersion(existing) && hasVersion(gav)) {
Review Comment:
💡 **Nit (readability):** The operator precedence here is correct (`!` > `&&`
> `||`, so this reads as `existing == null || (!hasVersion(existing) &&
hasVersion(gav))`), but it's non-obvious at a glance. Consider adding explicit
parentheses:
```suggestion
if (existing == null || (!hasVersion(existing) &&
hasVersion(gav))) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]