Skip to content

Commit

Permalink
Skip initial compile unless there is a compiler:compile error
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Kurz <[email protected]>
  • Loading branch information
scottkurz committed Dec 5, 2023
1 parent 704f6f7 commit e2e26eb
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou
List<File> resourceDirs, JavaCompilerOptions compilerOptions, String mavenCacheLocation,
List<ProjectModule> upstreamProjects, List<MavenProject> upstreamMavenProjects, boolean recompileDeps,
File pom, Map<String, List<String>> parentPoms, boolean generateFeatures, boolean skipInstallFeature,
Set<String> compileArtifactPaths, Set<String> testArtifactPaths, List<Path> webResourceDirs) throws IOException, PluginExecutionException {
Set<String> compileArtifactPaths, Set<String> testArtifactPaths, List<Path> webResourceDirs, boolean compileMojoError) throws IOException, PluginExecutionException {
super(new File(project.getBuild().getDirectory()), serverDirectory, sourceDirectory, testSourceDirectory,
configDirectory, projectDirectory, multiModuleProjectDirectory, resourceDirs, hotTests, skipTests,
skipUTs, skipITs, skipInstallFeature, project.getArtifactId(), serverStartTimeout, verifyTimeout, verifyTimeout,
((long) (compileWait * 1000L)), libertyDebug, false, false, pollingTest, container, containerfile,
containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts, compilerOptions,
keepTempContainerfile, mavenCacheLocation, upstreamProjects, recompileDeps, project.getPackaging(),
pom, parentPoms, generateFeatures, compileArtifactPaths, testArtifactPaths, webResourceDirs);
pom, parentPoms, generateFeatures, compileArtifactPaths, testArtifactPaths, webResourceDirs,compileMojoError);

this.libertyDirPropertyFiles = BasicSupport.getLibertyDirectoryPropertyFiles(installDir, userDir,
serverDirectory);
Expand Down Expand Up @@ -1258,6 +1258,8 @@ private boolean isUsingBoost() {
}

private void doDevMode() throws MojoExecutionException {
boolean compileMojoError = false;

String mvnVersion = runtime.getMavenVersion();
getLog().debug("Maven version: " + mvnVersion);
// Maven 3.8.2 and 3.8.3 contain a bug where compile artifacts are not resolved
Expand Down Expand Up @@ -1365,7 +1367,11 @@ private void doDevMode() throws MojoExecutionException {
getLog().debug("Skipping compile/resources on module with pom packaging type");
} else {
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources");
runCompileMojoLogWarning();
try {
runCompileMojoLogWarningWithException();
} catch (MojoExecutionException e) {
compileMojoError = true;
}
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "testResources");
runTestCompileMojoLogWarning();
}
Expand Down Expand Up @@ -1519,7 +1525,7 @@ private void doDevMode() throws MojoExecutionException {
util = new DevMojoUtil(installDirectory, userDirectory, serverDirectory, sourceDirectory, testSourceDirectory,
configDirectory, project.getBasedir(), multiModuleProjectDirectory, resourceDirs, compilerOptions,
settings.getLocalRepository(), upstreamProjects, upstreamMavenProjects, recompileDeps, pom, parentPoms,
generateFeatures, skipInstallFeature, compileArtifactPaths, testArtifactPaths, webResourceDirs);
generateFeatures, skipInstallFeature, compileArtifactPaths, testArtifactPaths, webResourceDirs, compileMojoError);
} catch (IOException | PluginExecutionException |DependencyResolutionRequiredException e) {
throw new MojoExecutionException("Error initializing dev mode.", e);
}
Expand Down Expand Up @@ -1932,6 +1938,24 @@ private void runCompileMojoLogWarning() throws MojoExecutionException {
runCompileMojo("compile", project);
updateArtifactPathToOutputDirectory(project);
}

private void runCompileMojoLogWarningWithException() throws MojoExecutionException {

String goal = "compile";

Plugin plugin = getPluginForProject("org.apache.maven.plugins", "maven-compiler-plugin", project);
MavenSession tempSession = session.clone();
tempSession.setCurrentProject(project);
MavenProject tempProject = project;
Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(plugin, goal, getLog());
config = Xpp3Dom.mergeXpp3Dom(configuration(element(name("failOnError"), "true")), config);
getLog().info("Running maven-compiler-plugin:" + goal + " on " + tempProject.getFile());
getLog().debug("configuration:\n" + config);
executeMojo(plugin, goal(goal), config, executionEnvironment(tempProject, tempSession, pluginManager));

updateArtifactPathToOutputDirectory(project);
}


/**
* Executes maven:compile but logs errors as warning messages
Expand Down

0 comments on commit e2e26eb

Please sign in to comment.