From 70a58f78e3223b678f82278a92e9a9c423911e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Wed, 20 Dec 2023 12:53:28 +0100 Subject: [PATCH] Fix "m2e plugin sometimes 'loses' resources" (#1511) The Java Builder may delete files from the project output directory that need to be re-created by the m2e Maven Builder. With commit 8e5cd4967eaca2698e8f7109461320e11a11d4d7 (a fix for #1275), any changes to the project output directory were ignored, leading to unexpected errors when running an application after modifying the project POM: resources were missing from the target classpath, leading all sorts of unexpected program behavior. This change allows marking these changes as relevant, as long as the following conditions are met: - The expected resource no longer exists (i.e., it was deleted by another builder, plugin or outside process) - The modification applies to a resource in the classes or test-classes folder (i.e., outputLocation/testOutputLocation) https://github.com/eclipse-m2e/m2e-core/issues/1511 https://github.com/eclipse-m2e/m2e-core/issues/1275 --- .../m2e/core/internal/builder/MavenBuilderImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java index 6b88fda39..a86e5cabc 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java @@ -209,6 +209,10 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel if(project == null || buildOutputLocation == null) { return true; } + + IPath outputLocation = projectFacade.getOutputLocation(); + IPath testOutputLocation = projectFacade.getTestOutputLocation(); + IPath projectPath = project.getFullPath(); List moduleLocations = projectFacade.getMavenProjectModules().stream() .map(module -> projectPath.append(module)).toList(); @@ -219,7 +223,12 @@ private boolean hasRelevantDelta(IMavenProjectFacade projectFacade, IResourceDel IPath fullPath = delta.getFullPath(); if(buildOutputLocation.isPrefixOf(fullPath)) { //anything in the build output is not interesting for a change as it is produced by the build - //lets see if there are more interesting parts... + // ... unless a classpath resource that existed before has been deleted, possibly by another builder + if(!resource.exists() && ((outputLocation != null && outputLocation.isPrefixOf(fullPath)) + || (testOutputLocation != null && testOutputLocation.isPrefixOf(fullPath)))) { + hasRelevantDelta.set(true); + return false; + } return true; } for(IPath modulePath : moduleLocations) {