我安装了一些较旧版本的 grails (3.3.8),并尝试使用 sdkman 安装较新版本 (4.0.4)。安装成功了,但 grails 现在完全崩溃了。我还从 oracle 网站的 dmg 将 java 更新为 14。基本上 grails 现在完全崩溃了。任何想法如何解决?
mac 10.14.4
$ sdk version
SDKMAN 5.7.3+337
$ sdk current java
Not using any version of java
$ java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
$ sdk current
Using:
groovy: 2.5.8
$ grails --version
| Grails Version: 3.3.8
| Groovy Version: 2.4.15
| JVM Version: 14.0.2
$ sdk install grails
Downloading: grails 4.0.4
In progress...
######################################################################## 100.0%
Installing: grails 4.0.4
Done installing!
Setting grails 4.0.4 as default.
$ sdk current
Using:
groovy: 2.5.8
$ grails --version
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:107)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:107)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.bitwiseNegate(ScriptBytecodeAdapter.java:842)
at org.grails.config.NavigableMap.<clinit>(NavigableMap.groovy)
at org.grails.cli.GrailsCli.<clinit>(GrailsCli.groovy:77)
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:124)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:346)
at java.base/java.lang.Class.newInstance(Class.java:604)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.createMetaMethodFromClass(MetaClassRegistryImpl.java:257)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:86)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.bitwiseNegate(ScriptBytecodeAdapter.java:842)
at org.grails.config.NavigableMap.<clinit>(NavigableMap.groovy)
at org.grails.cli.GrailsCli.<clinit>(GrailsCli.groovy:77)
我没有看到卸载 java 14 或及时返回的简单方法。
echo $PATH
/Users/xx/.sdkman/candidates/groovy/current/bin:/Users/xx/.sdkman/candidates/grails/current/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Appz/apache-jmeter-5.3/bin:/usr/local/go/bin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/xx/go/bin:/Users/xx/dev/grails-3.3.8/bin:/Users/xx/dev/flutter/bin:/Users/xx/dev/gradle-5.1.1/bin:/appz/cassandra/bin
我猜我可以尝试破解路径等来修复。
这是我当前的 .bash_profile:
vi .bash_profile
export JAVA_HOME=`/usr/libexec/java_home`
export GRAILS_HOME=/Users/xx/dev/grails-3.3.8
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
export PATH=$PATH:$GRAILS_HOME/bin
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
export GRADLE_HOME=/Users/xx/dev/gradle-5.1.1
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
PATH="${PATH}:/Users/xx/dev/flutter/bin"
PATH=$PATH:$GRADLE_HOME/bin
# Cassandra
if [ -d "/appz/cassandra" ]; then
export PATH="$PATH:/appz/cassandra/bin"
fi
export PATH
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/Users/simonh/.sdkman"
[[ -s "/Users/xx/.sdkman/xx/sdkman-init.sh" ]] && source "/Users/xx/.sdkman/bin/sdkman-init.sh"
~
这很奇怪,为什么当 sdkman 安装并使 4.0.4 成为当前版本时,grails home 仍然是 3.3.8?为什么不编辑路径?我应该将 gradle 设置为哪个版本?我如何回到 java 8,因为我认为 java 14 中存在导致 grails 问题的错误?