Skip to content

Commit

Permalink
Removed distinct() in TaskFactory and added a test in AbstractBuildMo…
Browse files Browse the repository at this point in the history
…jo instead (root cause)
  • Loading branch information
salmonb committed May 31, 2024
1 parent 1964519 commit eaec93d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected List<Project> scope(Collection<? extends Dependency> dependencies, Dep
return dependencies.stream()
.filter(d -> ((com.vertispan.j2cl.build.Dependency) d).belongsToScope(scope))
.map(Dependency::getProject)
.distinct()
.collect(Collectors.toUnmodifiableList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit eaec93d

Please sign in to comment.