gnodet commented on code in PR #12993:
URL: https://github.com/apache/maven/pull/12993#discussion_r3913100429


##########
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/NashornCompatibilityStrategy.java:
##########
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.cling.invoker.mvnup.goals;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import eu.maveniverse.domtrip.Document;
+import eu.maveniverse.domtrip.Element;
+import org.apache.maven.api.cli.mvnup.UpgradeOptions;
+import org.apache.maven.api.di.Named;
+import org.apache.maven.api.di.Priority;
+import org.apache.maven.api.di.Singleton;
+import org.apache.maven.cling.invoker.mvnup.UpgradeContext;
+
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.ARTIFACT_ID;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.BUILD;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.DEPENDENCIES;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.GROUP_ID;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGIN;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGINS;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGIN_MANAGEMENT;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PROFILE;
+import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PROFILES;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Plugins.DEFAULT_MAVEN_PLUGIN_GROUP_ID;
+
+/**
+ * Strategy for injecting the standalone OpenJDK Nashorn engine as a plugin 
dependency
+ * when {@code maven-antrun-plugin} uses inline JavaScript via {@code <script 
language="javascript">}.
+ *
+ * <p>Maven 4 requires JDK 17+, but the built-in Nashorn JavaScript engine was 
removed in JDK 15.
+ * Plugins executing JavaScript in-process (particularly {@code 
maven-antrun-plugin} with
+ * {@code <script language="javascript">}) fail with:
+ * <pre>
+ * [ERROR] Unable to create javax script engine for javascript
+ * </pre>
+ *
+ * <p>Toolchains cannot help because the script runs in Maven's own JVM, not 
in a forked process.
+ * The standalone OpenJDK Nashorn ({@code org.openjdk.nashorn:nashorn-core}) 
provides a drop-in
+ * replacement that registers via {@code ServiceLoader} and restores 
JavaScript support.
+ *
+ * @see <a href="https://github.com/apache/maven/issues/12988";>#12988</a>
+ */
+@Named
+@Singleton
+@Priority(19)
+public class NashornCompatibilityStrategy extends AbstractUpgradeStrategy {

Review Comment:
   Good point — doing both now. Updated in 893788e to:
   
   1. **Inject** `nashorn-core` as the quick fix (so the build doesn't break on 
day one)
   2. **Warn** that users should consider migrating to GraalVM JavaScript 
(`org.graalvm.js:js-scriptengine` + `org.graalvm.js:js`) for long-term support
   
   The warning message reads:
   > maven-antrun-plugin uses inline JavaScript which requires a standalone 
script engine on JDK 17+. Adding org.openjdk.nashorn:nashorn-core as a quick 
fix. Consider migrating to GraalVM JavaScript (org.graalvm.js:js-scriptengine + 
org.graalvm.js:js) for long-term support.
   
   This way mvnup unblocks the upgrade immediately while nudging users toward 
the more modern stack.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to