Repository: quarkusio/quarkus
Issue: Quarkus master / dev mode / --enable-preview - compilation fails after .java file edit

Quarkus master / dev mode / --enable-preview - compilation fails after .java file edit

https://github.com/quarkusio/quarkus/pull/8279 should make dev mode ready to work with `--enable-preview` flag, but I'm struggling with it. Tried on Java 14 and Java 15ea and Quarkus master 079cf3925c

I can run dev mode, simple rest endpoint provides the content, it blows up when the simple jaxrs resource is edited, compilation fails, `java.lang.RuntimeException: Compilation failed[error: --enable-preview must be used with either -source or --release]` is returned by the endpoint.

Reproducer:
```
git clone https://github.com/rsvoboda/quarkus-jdk15.git
cd quarkus-jdk15
sdk use java 15.ea.21-open
mvn quarkus:dev
curl http://localhost:8080/hello    ## hello
edit ./src/main/java/io/quarkus/qe/jdk/Jdk15Resource.java
curl http://localhost:8080/hello    ## java.lang.RuntimeException: Compilation failed[error: --enable-preview must be used with either -source or --release]

```

Changed files:
devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java

diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
index 46ce6ec9bdb..930f71095ac 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Properties;
 import java.util.Queue;
 import java.util.Set;
@@ -546,26 +547,15 @@ void prepare() throws Exception {
             devModeContext.getBuildSystemProperties().putIfAbsent("quarkus.application.version", project.getVersion());
 
             devModeContext.setSourceEncoding(getSourceEncoding());
-            devModeContext.setSourceJavaVersion(source);
-            devModeContext.setTargetJvmVersion(target);
 
             // Set compilation flags.  Try the explicitly given configuration first.  Otherwise,
             // refer to the configuration of the Maven Compiler Plugin.
+            final Optional<Xpp3Dom> compilerPluginConfiguration = findCompilerPluginConfiguration();
             if (compilerArgs != null) {
                 devModeContext.setCompilerOptions(compilerArgs);
-            } else {
-                for (Plugin plugin : project.getBuildPlugins()) {
-                    if (!plugin.getKey().equals("org.apache.maven.plugins:maven-compiler-plugin")) {
-                        continue;
-                    }
-                    Xpp3Dom compilerPluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
-                    if (compilerPluginConfiguration == null) {
-                        continue;
-                    }
-                    Xpp3Dom compilerPluginArgsConfiguration = compilerPluginConfiguration.getChild("compilerArgs");
-                    if (compilerPluginArgsConfiguration == null) {
-                        continue;
-                    }
+            } else if (compilerPluginConfiguration.isPresent()) {
+                final Xpp3Dom compilerPluginArgsConfiguration = compilerPluginConfiguration.get().getChild("compilerArgs");
+                if (compilerPluginArgsConfiguration != null) {
                     List<String> compilerPluginArgs = new ArrayList<>();
                     for (Xpp3Dom argConfiguration : compilerPluginArgsConfiguration.getChildren()) {
                         compilerPluginArgs.add(argConfiguration.getValue());
@@ -576,7 +566,24 @@ void prepare() throws Exception {
                         compilerPluginArgs.add(compilerPluginArgsConfiguration.getValue().trim());
                     }
                     devModeContext.setCompilerOptions(compilerPluginArgs);
-                    break;
+                }
+            }
+            if (source != null) {
+                devModeContext.setSourceJavaVersion(source);
+            } else if (compilerPluginConfiguration.isPresent()) {
+                final Xpp3Dom javacSourceVersion = compilerPluginConfiguration.get().getChild("source");
+                if (javacSourceVersion != null && javacSourceVersion.getValue() != null
+                        && !javacSourceVersion.getValue().trim().isEmpty()) {
+                    devModeContext.setSourceJavaVersion(javacSourceVersion.getValue().trim());
+                }
+            }
+            if (target != null) {
+                devModeContext.setTargetJvmVersion(target);
+            } else if (compilerPluginConfiguration.isPresent()) {
+                final Xpp3Dom javacTargetVersion = compilerPluginConfiguration.get().getChild("target");
+                if (javacTargetVersion != null && javacTargetVersion.getValue() != null
+                        && !javacTargetVersion.getValue().trim().isEmpty()) {
+                    devModeContext.setTargetJvmVersion(javacTargetVersion.getValue().trim());
                 }
             }
 
@@ -856,4 +863,17 @@ private List<LocalProject> filterExtensionDependencies(LocalProject localProject
         }
         return ret;
     }
+
+    private Optional<Xpp3Dom> findCompilerPluginConfiguration() {
+        for (final Plugin plugin : project.getBuildPlugins()) {
+            if (!plugin.getKey().equals("org.apache.maven.plugins:maven-compiler-plugin")) {
+                continue;
+            }
+            final Xpp3Dom compilerPluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
+            if (compilerPluginConfiguration != null) {
+                return Optional.of(compilerPluginConfiguration);
+            }
+        }
+        return Optional.empty();
+    }
 }