Skip to content

Commit

Permalink
Only include bootstrap dependencies in quarkus:dev ClassPath
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartwdouglas committed Oct 22, 2020
1 parent 6312680 commit 847ece9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<AppArtifactKey> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 847ece9

Please sign in to comment.