From 847ece98fa44615530d6a49aeffdad6e7adba337 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 17 Sep 2020 14:15:34 +1000 Subject: [PATCH] Only include bootstrap dependencies in quarkus:dev ClassPath The rest of the depenencies are resolved in the bootstrap resolver, having them on the ClassPath only causes problems. A similar fix could be applied to Gradle, however I am not sure how to filter the dependencies to only include those required for bootstrap. Fixes #12136 --- .../main/java/io/quarkus/maven/DevMojo.java | 31 +++++++++++++++++-- .../bootstrap/model/AppArtifactKey.java | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index ce34e442a0a26..e2c54c2029a8c 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -38,6 +38,7 @@ import java.util.jar.Manifest; import java.util.stream.Collectors; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; import org.apache.maven.artifact.Artifact; @@ -75,6 +76,7 @@ import org.eclipse.aether.util.artifact.JavaScopes; import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.bootstrap.model.AppModel; import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions; import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject; import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace; @@ -93,6 +95,7 @@ */ @Mojo(name = "dev", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) public class DevMojo extends AbstractMojo { + private static final String EXT_PROPERTIES_PATH = "META-INF/quarkus-extension.properties"; /** * running any one of these phases means the compile phase will have been run, if these have @@ -717,11 +720,35 @@ void prepare(final boolean triggerCompile) throws Exception { //in most cases these are not used, however they need to be present for some //parent-first cases such as logging + //first we go through and get all the parent first artifacts + Set parentFirstArtifacts = new HashSet<>(); + for (Artifact appDep : project.getArtifacts()) { + if (appDep.getArtifactHandler().getExtension().equals("jar") && appDep.getFile().isFile()) { + try (ZipFile file = new ZipFile(appDep.getFile())) { + ZipEntry entry = file.getEntry(EXT_PROPERTIES_PATH); + if (entry != null) { + Properties p = new Properties(); + try (InputStream inputStream = file.getInputStream(entry)) { + p.load(inputStream); + String parentFirst = p.getProperty(AppModel.PARENT_FIRST_ARTIFACTS); + if (parentFirst != null) { + String[] artifacts = parentFirst.split(","); + for (String artifact : artifacts) { + parentFirstArtifacts.add(new AppArtifactKey(artifact.split(":"))); + } + } + } + + } + } + } + } for (Artifact appDep : project.getArtifacts()) { // only add the artifact if it's present in the dev mode context // we need this to avoid having jars on the classpath multiple times - if (!devModeContext.getLocalArtifacts().contains(new AppArtifactKey(appDep.getGroupId(), appDep.getArtifactId(), - appDep.getClassifier(), appDep.getArtifactHandler().getExtension()))) { + AppArtifactKey key = new AppArtifactKey(appDep.getGroupId(), appDep.getArtifactId(), + appDep.getClassifier(), appDep.getArtifactHandler().getExtension()); + if (!devModeContext.getLocalArtifacts().contains(key) && parentFirstArtifacts.contains(key)) { addToClassPaths(classPathManifest, appDep.getFile()); } } diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactKey.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactKey.java index a9c1a96ef67b8..de336cb2d6efe 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactKey.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppArtifactKey.java @@ -70,7 +70,7 @@ protected static String[] split(String str, String[] parts, int fromIndex) { protected final String classifier; protected final String type; - protected AppArtifactKey(String[] parts) { + public AppArtifactKey(String[] parts) { this.groupId = parts[0]; this.artifactId = parts[1]; if (parts.length == 2 || parts[2] == null) {