diff --git a/vaadin-testbench-loadtest/testbench-converter-plugin/src/main/java/com/vaadin/testbench/loadtest/AbstractRecordMojo.java b/vaadin-testbench-loadtest/testbench-converter-plugin/src/main/java/com/vaadin/testbench/loadtest/AbstractRecordMojo.java index 2d70aa7e7..21ff6e793 100644 --- a/vaadin-testbench-loadtest/testbench-converter-plugin/src/main/java/com/vaadin/testbench/loadtest/AbstractRecordMojo.java +++ b/vaadin-testbench-loadtest/testbench-converter-plugin/src/main/java/com/vaadin/testbench/loadtest/AbstractRecordMojo.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; @@ -114,6 +115,16 @@ public abstract class AbstractRecordMojo extends AbstractK6Mojo { @Parameter(property = "k6.thinkTime.interactionDelay", defaultValue = "0.5") protected double interactionDelay; + /** + * Current Maven session. Used to propagate the active local repository and + * user settings file to the forked Maven that runs the recorded test, so + * the fork resolves project SNAPSHOTs from the same repository the outer + * build is using (e.g. the maven-invoker-plugin's isolated + * {@code target/local-repo}). + */ + @Parameter(defaultValue = "${session}", readonly = true, required = true) + protected MavenSession session; + protected SourceHasher sourceHasher; /** @@ -344,6 +355,27 @@ protected List buildBaseTestCommand(String currentTestClass) { command.add("-Dserver.port=" + appPort); command.add("-DfailIfNoTests=false"); + // Propagate the outer build's local repository and settings to the + // fork. The maven-invoker-plugin runs ITs against an isolated + // target/local-repo containing freshly built SNAPSHOTs that the + // user's ~/.m2 does not have; without this, the fork resolves + // against ~/.m2 alone and fails to find e.g. vaadin-testbench-*: + // 10.2-SNAPSHOT. + if (session != null) { + if (session.getLocalRepository() != null + && session.getLocalRepository().getBasedir() != null) { + command.add("-Dmaven.repo.local=" + + session.getLocalRepository().getBasedir()); + } + File userSettings = session.getRequest() != null + ? session.getRequest().getUserSettingsFile() + : null; + if (userSettings != null && userSettings.isFile()) { + command.add("-s"); + command.add(userSettings.getAbsolutePath()); + } + } + if (mavenArgs != null && !mavenArgs.isEmpty()) { for (String arg : mavenArgs.split("\\s+")) { command.add(arg);