diff --git a/org.eclipse.m2e.jdt.tests/projects/enforcerSettingsWithoutRequiredJavaVersion/pom.xml b/org.eclipse.m2e.jdt.tests/projects/enforcerSettingsWithoutRequiredJavaVersion/pom.xml
new file mode 100644
index 0000000000..cece53e90f
--- /dev/null
+++ b/org.eclipse.m2e.jdt.tests/projects/enforcerSettingsWithoutRequiredJavaVersion/pom.xml
@@ -0,0 +1,47 @@
+
+
+ 4.0.0
+ foo.bar
+ demo
+ 0.0.1-SNAPSHOT
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.10.1
+
+
+ 1.8
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 3.1.0
+
+
+ enforce-java-version
+
+ enforce
+
+ validate
+
+
+
+ No Releases Allowed!
+
+
+
+
+
+
+
+
+
diff --git a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationFromEnforcer.java b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationFromEnforcerTest.java
similarity index 77%
rename from org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationFromEnforcer.java
rename to org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationFromEnforcerTest.java
index acab42fbf4..704103c327 100644
--- a/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationFromEnforcer.java
+++ b/org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/JavaConfigurationFromEnforcerTest.java
@@ -27,11 +27,11 @@
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
import org.junit.Test;
-public class JavaConfigurationFromEnforcer extends AbstractMavenProjectTestCase {
+public class JavaConfigurationFromEnforcerTest extends AbstractMavenProjectTestCase {
private static final String JRE_CONTAINER_PREFIX = "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/";
@Test
- public void testEnforcerVersion() throws Exception {
+ public void testEnforcer_Version() throws Exception {
IProject project = importProject("projects/enforcerSettingsWithVersion/pom.xml");
waitForJobsToComplete();
IJavaProject jproject = JavaCore.create(project);
@@ -41,7 +41,7 @@ public void testEnforcerVersion() throws Exception {
}
@Test
- public void testEnforcerVersionRange() throws Exception {
+ public void testEnforcer_VersionRange() throws Exception {
IProject project = importProject("projects/enforcerSettingsWithVersionRange/pom.xml");
waitForJobsToComplete();
IJavaProject jproject = JavaCore.create(project);
@@ -50,6 +50,17 @@ public void testEnforcerVersionRange() throws Exception {
assertEquals(List.of("JavaSE-11"), getJREContainerVMType(jproject));
}
+ @Test
+ public void testEnforcer_NoVersionRange() throws Exception {
+ IProject project = importProject("projects/enforcerSettingsWithoutRequiredJavaVersion/pom.xml");
+ waitForJobsToComplete();
+ IJavaProject jproject = JavaCore.create(project);
+ assertEquals("1.8", jproject.getOption(JavaCore.COMPILER_SOURCE, false));
+ assertEquals("1.8", jproject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, false));
+ assertEquals(List.of("JavaSE-1.8"), getJREContainerVMType(jproject));
+ }
+
+
private static List getJREContainerVMType(IJavaProject jproject) throws JavaModelException {
return Arrays.stream(jproject.getRawClasspath())
.filter(cp -> cp.getEntryKind() == IClasspathEntry.CPE_CONTAINER).map(IClasspathEntry::getPath)
diff --git a/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF b/org.eclipse.m2e.jdt/META-INF/MANIFEST.MF
index b7c512a028..6c77ffb711 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.0.3.qualifier
+Bundle-Version: 2.0.4.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 b589e69646..09a7654f00 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
@@ -862,6 +862,9 @@ private String getMinimumJavaBuildEnvironmentId(MavenProject mavenProject, MojoE
// https://maven.apache.org/enforcer/enforcer-rules/requireJavaVersion.html
String version = ((MavenImpl) maven).getMojoParameterValue(mavenProject, mojoExecution,
List.of("rules", "requireJavaVersion", "version"), String.class, monitor);
+ if(version == null) {
+ return null;
+ }
return getMinimumJavaBuildEnvironmentId(version);
}