diff --git a/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java index bac5869a23d8e..20b82611c5190 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java @@ -2,7 +2,7 @@ import java.lang.reflect.Method; import java.nio.file.Path; -import java.nio.file.Paths; +import java.util.List; import java.util.Properties; import java.util.function.Consumer; @@ -50,12 +50,11 @@ protected boolean beforeExecute() throws MojoExecutionException, MojoFailureExce @Override protected void doExecute() throws MojoExecutionException, MojoFailureException { - String projectDir = mavenProject().getBasedir().getAbsolutePath(); - Path sourcesDir = Paths.get(projectDir, "src", "main"); - generateCode(sourcesDir, path -> mavenProject().addCompileSourceRoot(path.toString()), false); + generateCode(getParentDirs(mavenProject().getCompileSourceRoots()), + path -> mavenProject().addCompileSourceRoot(path.toString()), false); } - void generateCode(Path sourcesDir, + void generateCode(PathCollection sourceParents, Consumer sourceRegistrar, boolean test) throws MojoFailureException, MojoExecutionException { @@ -78,7 +77,7 @@ void generateCode(Path sourcesDir, Path.class, Path.class, Consumer.class, ApplicationModel.class, Properties.class, String.class, boolean.class); - initAndRun.invoke(null, deploymentClassLoader, PathList.of(sourcesDir), + initAndRun.invoke(null, deploymentClassLoader, sourceParents, generatedSourcesDir(test), buildDir().toPath(), sourceRegistrar, curatedApplication.getApplicationModel(), mavenProject().getProperties(), launchMode.name(), @@ -94,6 +93,20 @@ void generateCode(Path sourcesDir, } } + protected PathCollection getParentDirs(List sourceDirs) { + if (sourceDirs.size() == 1) { + return PathList.of(Path.of(sourceDirs.get(0)).getParent()); + } + final PathList.Builder builder = PathList.builder(); + for (int i = 0; i < sourceDirs.size(); ++i) { + final Path parentDir = Path.of(sourceDirs.get(i)).getParent(); + if (!builder.contains(parentDir)) { + builder.add(parentDir); + } + } + return builder.build(); + } + private Path generatedSourcesDir(boolean test) { return test ? buildDir().toPath().resolve("generated-test-sources") : buildDir().toPath().resolve("generated-sources"); } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeTestsMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeTestsMojo.java index 9bb919395ca9c..a5a2644e8f16c 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeTestsMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeTestsMojo.java @@ -1,8 +1,5 @@ package io.quarkus.maven; -import java.nio.file.Path; -import java.nio.file.Paths; - import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -13,8 +10,7 @@ public class GenerateCodeTestsMojo extends GenerateCodeMojo { @Override protected void doExecute() throws MojoExecutionException, MojoFailureException { - String projectDir = mavenProject().getBasedir().getAbsolutePath(); - Path testSources = Paths.get(projectDir, "src", "test"); - generateCode(testSources, path -> mavenProject().addTestCompileSourceRoot(path.toString()), true); + generateCode(getParentDirs(mavenProject().getTestCompileSourceRoots()), + path -> mavenProject().addTestCompileSourceRoot(path.toString()), true); } -} \ No newline at end of file +} 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 41c4634d1d3c7..9fb1554c640c3 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 @@ -146,7 +146,7 @@ public AppModelResolver getAppModelResolver() { if (mavenArtifactResolver == null) { final BootstrapMavenContext mvnCtx = createBootstrapMavenContext(); if (managingProject == null) { - managingProject = mvnCtx.getCurrentProjectArtifact("pom"); + managingProject = mvnCtx.getCurrentProjectArtifact(ArtifactCoords.TYPE_POM); } mvn = new MavenArtifactResolver(mvnCtx); } else {