diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/BootstrapAppModelFactory.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/BootstrapAppModelFactory.java index 71f006026..609eef9cd 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/BootstrapAppModelFactory.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/BootstrapAppModelFactory.java @@ -80,6 +80,8 @@ public class BootstrapAppModelFactory { private LocalProject appClassesWorkspace; + private List forcedDependencies = Collections.emptyList(); + private BootstrapAppModelFactory() { } @@ -143,6 +145,11 @@ public class BootstrapAppModelFactory { return this; } + public BootstrapAppModelFactory setForcedDependencies(List forcedDependencies) { + this.forcedDependencies = forcedDependencies; + return this; + } + public AppModelResolver getAppModelResolver() { if (bootstrapAppModelResolver != null) { @@ -273,7 +280,7 @@ public class BootstrapAppModelFactory { } AppModelResolver appModelResolver = getAppModelResolver(); CurationResult curationResult = new CurationResult(appModelResolver - .resolveManagedModel(appArtifact, Collections.emptyList(), managingProject)); + .resolveManagedModel(appArtifact, forcedDependencies, managingProject)); if (cachedCpPath != null) { Files.createDirectories(cachedCpPath.getParent()); try (DataOutputStream out = new DataOutputStream(Files.newOutputStream(cachedCpPath))) { diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java index 980ceaa29..ede1400a6 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java @@ -3,6 +3,7 @@ package io.quarkus.bootstrap.app; import io.quarkus.bootstrap.BootstrapAppModelFactory; import io.quarkus.bootstrap.BootstrapException; import io.quarkus.bootstrap.model.AppArtifact; +import io.quarkus.bootstrap.model.AppDependency; import io.quarkus.bootstrap.resolver.AppModelResolver; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.bootstrap.resolver.update.DependenciesOrigin; @@ -72,6 +73,7 @@ public class QuarkusBootstrap implements Serializable { private final boolean isolateDeployment; private final MavenArtifactResolver mavenArtifactResolver; private final AppArtifact managingProject; + private final List forcedDependencies; private QuarkusBootstrap(Builder builder) { this.applicationRoot = builder.applicationRoot; @@ -95,6 +97,7 @@ public class QuarkusBootstrap implements Serializable { this.additionalDeploymentArchives = builder.additionalDeploymentArchives; this.mavenArtifactResolver = builder.mavenArtifactResolver; this.managingProject = builder.managingProject; + this.forcedDependencies = new ArrayList<>(builder.forcedDependencies); } public CuratedApplication bootstrap() throws BootstrapException { @@ -119,6 +122,7 @@ public class QuarkusBootstrap implements Serializable { .setLocalProjectsDiscovery(localProjectDiscovery) .setAppArtifact(appArtifact) .setManagingProject(managingProject) + .setForcedDependencies(forcedDependencies) .setAppClasses(getProjectRoot() != null ? getProjectRoot() : getApplicationRoot()); if (mode == Mode.TEST || test) { @@ -213,6 +217,7 @@ public class QuarkusBootstrap implements Serializable { boolean isolateDeployment; MavenArtifactResolver mavenArtifactResolver; AppArtifact managingProject; + List forcedDependencies = new ArrayList<>(); public Builder(Path applicationRoot) { this.applicationRoot = applicationRoot; @@ -329,6 +334,15 @@ public class QuarkusBootstrap implements Serializable { return this; } + /** + * If set, each of these dependencies will either be added to the application dependencies if the GA doesn't match any + * application dependencies, or override the existing version if the GA does match + */ + public Builder setForcedDependencies(List forcedDependencies) { + this.forcedDependencies = forcedDependencies; + return this; + } + public QuarkusBootstrap build() { return new QuarkusBootstrap(this); } diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java index 0472a874f..4821f67e0 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusProdModeTest.java @@ -15,6 +15,7 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -42,6 +43,8 @@ import io.quarkus.bootstrap.app.AugmentAction; import io.quarkus.bootstrap.app.AugmentResult; import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.app.QuarkusBootstrap; +import io.quarkus.bootstrap.model.AppArtifact; +import io.quarkus.bootstrap.model.AppDependency; import io.quarkus.test.common.PathTestHelper; import io.quarkus.test.common.RestAssuredURLManager; import io.quarkus.utilities.JavaBinFinder; @@ -84,6 +87,7 @@ public class QuarkusProdModeTest private Optional prodModeTestResultsField = Optional.empty(); private Path logfilePath; private Optional logfileField = Optional.empty(); + private List forcedDependencies = Collections.emptyList(); public Supplier getArchiveProducer() { return archiveProducer; @@ -148,6 +152,15 @@ public class QuarkusProdModeTest return this; } + /** + * Provides a convenient way to either add additional dependencies to the application (if it doesn't already contain a + * dependency), or override a version (if the dependency already exists) + */ + public QuarkusProdModeTest setForcedDependencies(List forcedDependencies) { + this.forcedDependencies = forcedDependencies; + return this; + } + private void exportArchive(Path deploymentDir, Class testClass) { try { JavaArchive archive = getArchiveProducerOrDefault(); @@ -229,7 +242,9 @@ public class QuarkusProdModeTest .setLocalProjectDiscovery(true) .addExcludedPath(testLocation) .setProjectRoot(testLocation) - .setTargetDirectory(buildDir); + .setTargetDirectory(buildDir) + .setForcedDependencies(forcedDependencies.stream().map(d -> new AppDependency(d, "compile")) + .collect(Collectors.toList())); if (applicationName != null) { builder.setBaseName(applicationName); }