diff --git a/build-caching/src/main/java/com/vertispan/j2cl/build/Dependency.java b/build-caching/src/main/java/com/vertispan/j2cl/build/Dependency.java index 1eb7d477..05692449 100644 --- a/build-caching/src/main/java/com/vertispan/j2cl/build/Dependency.java +++ b/build-caching/src/main/java/com/vertispan/j2cl/build/Dependency.java @@ -15,6 +15,8 @@ */ package com.vertispan.j2cl.build; +import java.util.Objects; + /** * A dependency is a reference to another project's contents, scoped to indicate whether these are * required to be compiled against, or linked against (and so are required at runtime). The default @@ -59,4 +61,20 @@ public Scope getScope() { public void setScope(Scope scope) { this.scope = scope; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Dependency that = (Dependency) o; + return Objects.equals(project, that.project) && Objects.equals(scope, that.scope); + } + + @Override + public int hashCode() { + int result = Objects.hashCode(project); + result = 31 * result + Objects.hashCode(scope); + return result; + } } diff --git a/build-caching/src/main/java/com/vertispan/j2cl/build/task/TaskFactory.java b/build-caching/src/main/java/com/vertispan/j2cl/build/task/TaskFactory.java index 5ac47414..78316e45 100644 --- a/build-caching/src/main/java/com/vertispan/j2cl/build/task/TaskFactory.java +++ b/build-caching/src/main/java/com/vertispan/j2cl/build/task/TaskFactory.java @@ -67,7 +67,6 @@ protected List scope(Collection dependencies, Dep return dependencies.stream() .filter(d -> ((com.vertispan.j2cl.build.Dependency) d).belongsToScope(scope)) .map(Dependency::getProject) - .distinct() .collect(Collectors.toUnmodifiableList()); } diff --git a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/AbstractBuildMojo.java b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/AbstractBuildMojo.java index 2b6f751b..bca7d922 100644 --- a/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/AbstractBuildMojo.java +++ b/j2cl-maven-plugin/src/main/java/com/vertispan/j2cl/mojo/AbstractBuildMojo.java @@ -345,7 +345,11 @@ private Project buildProjectHelper(MavenProject mavenProject, Artifact artifact, Dependency dep = new Dependency(); dep.setProject(child); dep.setScope(translateScope(mavenDependency.getScope())); - dependencies.add(dep); + // Although this new dependency is generally unique, the replacement mechanism may introduce a duplicate + // dependency if several original artifacts are replaced with the same final artifact. + if (!dependencies.contains(dep)) { // ensures we don't introduce a duplicate dependency (important for J2CL) + dependencies.add(dep); + } } project.setDependencies(dependencies);