diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java index 49da7cf0..bce9e5ad 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java @@ -89,7 +89,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { final SecurityManager sm = System.getSecurityManager(); try { if (!allowSystemExits) { - System.setSecurityManager(new NoExitSecurityManager()); + getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal."); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=disallow` to override this."); + } } // get classes we need with reflection @@ -129,7 +134,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); } finally { if (!allowSystemExits) { - System.setSecurityManager(sm); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=disallow` to override this."); + } } } } else { diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java index 976b2618..b2260c92 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java @@ -140,7 +140,12 @@ protected synchronized void doExecute() throws MojoExecutionException { final SecurityManager sm = System.getSecurityManager(); try { if (!allowSystemExits) { - System.setSecurityManager(new NoExitSecurityManager()); + getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal."); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=disallow` to override this."); + } } // get classes we need with reflection @@ -161,7 +166,11 @@ protected synchronized void doExecute() throws MojoExecutionException { throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); } finally { if (!allowSystemExits) { - System.setSecurityManager(sm); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=disallow` to override this."); + } } } } else { diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java index 112bf639..5640dfee 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java @@ -94,7 +94,12 @@ public void execute() throws MojoExecutionException { final SecurityManager sm = System.getSecurityManager(); try { if (!allowSystemExits) { - System.setSecurityManager(new NoExitSecurityManager()); + getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal."); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=disallow` to override this."); + } } // get classes we need with reflection @@ -123,7 +128,11 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); } finally { if (!allowSystemExits) { - System.setSecurityManager(sm); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=disallow` to override this."); + } } } } else {