Skip to content

Commit

Permalink
Keep same classpath order as surefire (#450)
Browse files Browse the repository at this point in the history
The elements' order on the classpath for native-image building must be
consistent with the testing time when the graalvm agent is enabled to
record the native image configurations.
  • Loading branch information
ziyilin authored Jul 12, 2023
1 parent 2988364 commit 1c4c174
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -321,15 +323,17 @@ protected void warnIfWrongMetaInfLayout(Path jarFilePath, Artifact artifact) thr

protected void addDependenciesToClasspath() throws MojoExecutionException {
configureMetadataRepository();
for (Artifact dependency : project.getArtifacts().stream()
.filter(artifact -> getDependencyScopes().contains(artifact.getScope()))
.collect(Collectors.toSet())) {
addArtifactToClasspath(dependency);
maybeAddDependencyMetadata(dependency, file -> {
buildArgs.add("--exclude-config");
buildArgs.add(Pattern.quote(dependency.getFile().getAbsolutePath()));
buildArgs.add("^/META-INF/native-image/");
});
Set<Artifact> collected = new HashSet<>();
// Must keep classpath order is the same with surefire test
for (Artifact dependency : project.getArtifacts()) {
if (getDependencyScopes().contains(dependency.getScope()) && collected.add(dependency)) {
addArtifactToClasspath(dependency);
maybeAddDependencyMetadata(dependency, file -> {
buildArgs.add("--exclude-config");
buildArgs.add(Pattern.quote(dependency.getFile().getAbsolutePath()));
buildArgs.add("^/META-INF/native-image/");
});
}
}
}

Expand Down

0 comments on commit 1c4c174

Please # to comment.