Skip to content

Commit 8790a30

Browse files
committed
Maven: enable configuring maven.top-level-basedir in quarkus:dev
The `quarkus:dev` goal now reads `maven.top-level-basedir` from its `systemProperties` configuration (which is potentically copied from Surefire if `copySurefireVariables` is set) and if set, configures the root project directory for the `BootstrapMavenContext`. This effectively means that the `maven.top-level-basedir` configuration may occur not just in a system property, but also in the POM.
1 parent 4a19ead commit 8790a30

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
101101
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
102102
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig;
103+
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
103104
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
104105
import io.quarkus.bootstrap.util.BootstrapUtils;
105106
import io.quarkus.bootstrap.workspace.ArtifactSources;
@@ -1408,6 +1409,18 @@ private DevModeCommandLine newLauncher(String actualDebugPort, String bootstrapI
14081409
if (appModel != null) {
14091410
bootstrapProvider.close();
14101411
} else {
1412+
Path rootProjectDir = null;
1413+
String topLevelBaseDirStr = systemProperties.get(BootstrapMavenContext.MAVEN_TOP_LEVEL_PROJECT_BASEDIR);
1414+
if (topLevelBaseDirStr != null) {
1415+
final Path tmp = Path.of(topLevelBaseDirStr);
1416+
if (!Files.exists(tmp)) {
1417+
throw new BootstrapMavenException("Top-level project base directory " + topLevelBaseDirStr
1418+
+ " specified with system property " + BootstrapMavenContext.MAVEN_TOP_LEVEL_PROJECT_BASEDIR
1419+
+ " does not exist");
1420+
}
1421+
rootProjectDir = tmp;
1422+
}
1423+
14111424
final BootstrapMavenContextConfig<?> mvnConfig = BootstrapMavenContext.config()
14121425
.setUserSettings(session.getRequest().getUserSettingsFile())
14131426
.setRemoteRepositories(repos)
@@ -1416,7 +1429,8 @@ private DevModeCommandLine newLauncher(String actualDebugPort, String bootstrapI
14161429
// it's important to set the base directory instead of the POM
14171430
// which maybe manipulated by a plugin and stored outside the base directory
14181431
.setCurrentProject(project.getBasedir().toString())
1419-
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties));
1432+
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties))
1433+
.setRootProjectDir(rootProjectDir);
14201434

14211435
// There are a couple of reasons we don't want to use the original Maven session:
14221436
// 1) a reload could be triggered by a change in a pom.xml, in which case the Maven session might not be in sync any more with the effective POM;

independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class BootstrapMavenContext {
9292
private static final String MAVEN_DOT_HOME = "maven.home";
9393
private static final String MAVEN_HOME = "MAVEN_HOME";
9494
private static final String MAVEN_SETTINGS = "maven.settings";
95-
private static final String MAVEN_TOP_LEVEL_PROJECT_BASEDIR = "maven.top-level-basedir";
95+
public static final String MAVEN_TOP_LEVEL_PROJECT_BASEDIR = "maven.top-level-basedir";
9696
private static final String SETTINGS_XML = "settings.xml";
9797
private static final String SETTINGS_SECURITY = "settings.security";
9898

0 commit comments

Comments
 (0)