How can I organize Emacs to run a specific external program with some specific environment/options for the mode or the buffer currently open.
My current solution is to use setenv
before running the external program, however it seems to change the environment for all the buffers in Emacs.
Example
To work around a bug in Groovy 3.0.0 (see below) I need to set some java option before running groovysh
. In terminal, I can do the following:
JAVA_OPTS=--add-opens=java.base/jdk.internal.jrtfs=ALL-UNNAMED groovysh
However, Emacs run groovysh
thanks to run-groovy
function from the inf-groovy.el file in groovy package. So I usually run eval-expression
with:
(setenv "JAVA_OPTS" "--add-opens=java.base/jdk.internal.jrtfs=ALL-UNNAMED")
which solves the problem, the inferior Groovy process is now working.
However, all my other buffers now use this value for this environment variable which is not desirable, since I need some other specific java options for other codes. My current solution is to invoke setenv
every time I change buffer.
groovysh 3.0.0 not working with jdk 11.0.6
Open a simple file in groovy mode and try to run-groovy
With Groovy 3.0.0 and JDK 11.0.6 installed it raises an error:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:111)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:129)
Caused by: java.lang.IllegalAccessException: class org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite cannot access class jdk.internal.jrtfs.JrtFileSystem (in module java.base) because module java.base does not export jdk.internal.jrtfs to unnamed module @6d4e5011
It took me a while to figure out that it was a problem due to version incompatibility between groovy and java, see https://issues.apache.org/jira/browse/GROOVY-9390