diff --git a/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/pom.xml b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/pom.xml
new file mode 100644
index 0000000000..5be51c1e2f
--- /dev/null
+++ b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/pom.xml
@@ -0,0 +1,21 @@
+
+
+ 4.0.0
+
+ parentproject
+ com.example
+ 1.0
+
+
+ app
+ app
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
diff --git a/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/src/main/java/.gitkeep b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/app/src/main/java/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/core/pom.xml b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/core/pom.xml
new file mode 100644
index 0000000000..139a4b44cb
--- /dev/null
+++ b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/core/pom.xml
@@ -0,0 +1,79 @@
+
+
+ 4.0.0
+
+ parentproject
+ com.example
+ 1.0
+
+
+ core
+
+ core
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 3.6.0
+
+
+
+ add-test-source
+
+ generate-test-sources
+
+
+
+ ${project.basedir}/../app/src/main/java
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.14.0
+
+
+
+
+
+ default-compile
+ none
+
+
+ default-testCompile
+ none
+
+
+ java-compile
+
+ compile
+
+ compile
+
+
+ java-test-compile
+
+ testCompile
+
+ test-compile
+
+
+
+
+
+
+
diff --git a/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/pom.xml b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/pom.xml
new file mode 100644
index 0000000000..9c938ce091
--- /dev/null
+++ b/org.eclipse.m2e.jdt.tests/projects/nonedefaultcompile/pom.xml
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+ com.example
+ parentproject
+ 1.0
+ parentproject
+
+ http://www.example.com
+ pom
+
+ UTF-8
+ 17
+
+
+
+ junit
+ junit
+ 4.13.1
+ test
+
+
+
+ core
+ app
+
+
+
diff --git a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationTest.java b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationTest.java
index 7f759b1f89..491f84f070 100644
--- a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationTest.java
+++ b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationTest.java
@@ -29,6 +29,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
@@ -228,6 +229,36 @@ public void testMultiReleaseJar() throws CoreException, IOException, Interrupted
}
}
+ @Test
+ public void testNonDefaultCompile() throws CoreException, IOException, InterruptedException {
+ File baseDir = new File(FileLocator
+ .toFileURL(JavaConfigurationTest.class.getResource("/projects/nonedefaultcompile/pom.xml")).getFile())
+ .getParentFile().getParentFile();
+ waitForJobsToComplete();
+ IProject project = importProjects(
+ baseDir.getAbsolutePath(), new String[] { "nonedefaultcompile/pom.xml",
+ "nonedefaultcompile/core/pom.xml", "nonedefaultcompile/app/pom.xml" },
+ new ResolverConfiguration())[0];
+ waitForJobsToComplete();
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject("core");
+ IJavaProject javaProject = JavaCore.create(project);
+ assertEquals("17", javaProject.getOption(JavaCore.COMPILER_SOURCE, false));
+ assertEquals("17", javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, false));
+ assertEquals("17", javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, false));
+ assertEquals(JavaCore.ENABLED, javaProject.getOption(JavaCore.COMPILER_RELEASE, false));
+
+ List srcEntryPaths = Arrays.stream(javaProject.getRawClasspath())
+ .filter(cp -> IClasspathEntry.CPE_SOURCE == cp.getEntryKind()).filter(cp -> !cp.isTest())
+ .map(IClasspathEntry::getPath).map(IPath::toString).toList();
+ assertEquals(Set.of("/core/src/main/java", "/core/src/main/resources"),
+ Set.copyOf(srcEntryPaths));
+ List testEntryPaths = Arrays.stream(javaProject.getRawClasspath())
+ .filter(cp -> IClasspathEntry.CPE_SOURCE == cp.getEntryKind()).filter(cp -> cp.isTest())
+ .map(IClasspathEntry::getPath).map(IPath::toString).toList();
+ assertEquals(Set.of("/core/src/test/java", "/core/src/test/resources",
+ "/core/.._app_src_main_java"),
+ Set.copyOf(testEntryPaths));
+ }
// --- utility methods ---
private static final Predicate TEST_SOURCES = cp -> cp.isTest()
diff --git a/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
index f3222241de..782f4ab69b 100644
--- a/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.jdt;singleton:=true
-Bundle-Version: 2.5.0.qualifier
+Bundle-Version: 2.5.1.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.m2e.jdt,
org.eclipse.m2e.jdt.internal;x-friends:="org.eclipse.m2e.jdt.ui",
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
index d5aa3d6ea3..c9f9169af2 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
@@ -733,9 +733,11 @@ protected void addJavaProjectOptions(Map options, ProjectConfigu
boolean enablePreviewFeatures = false;
+ boolean hasDefaultCompile = getCompilerMojoExecutions(request, monitor).stream()
+ .filter(e -> "default-compile".equals(e.getExecutionId())).findAny().isPresent();
for(MojoExecution execution : getCompilerMojoExecutions(request, monitor)) {
String id = execution.getExecutionId();
- if(!"default-compile".equals(id)) {
+ if(hasDefaultCompile && !"default-compile".equals(id)) {
//Maven can have many but JDT only supports one config!
continue;
}
@@ -990,7 +992,7 @@ private void removeMavenClasspathContainer(IProject project) throws JavaModelExc
protected IContainer getFolder(IProject project, String path) throws CoreException {
Path projectLocation = project.getLocation().toPath().toAbsolutePath();
- Path folderPath = Path.of(path);
+ Path folderPath = Path.of(path).normalize();
if(projectLocation.equals(folderPath)) {
return project;
}
@@ -1001,15 +1003,16 @@ protected IContainer getFolder(IProject project, String path) throws CoreExcepti
folderPath = projectLocation.resolve(path);
relativePath = IPath.fromOSString(path);
}
- if(!project.exists(relativePath) && Files.exists(folderPath)
+ IFolder folder = project.getFolder(relativePath);
+ if((!project.exists(relativePath) || !folder.getProject().equals(project)) && Files.exists(folderPath)
&& !ResourcesPlugin.getWorkspace().getRoot().getLocation().toPath().equals(folderPath)) {
String linkName = projectLocation.relativize(folderPath).toString().replace("/", "_");
- IFolder folder = project.getFolder(linkName);
+ folder = project.getFolder(linkName);
createLinkWithRetry(folder, folderPath.toUri());
folder.setPersistentProperty(LINKED_MAVEN_RESOURCE, "true");
return folder;
}
- return project.getFolder(relativePath);
+ return folder;
}
/**