由于 "Could not determine java version" 错误,无法对 Mac 上的新项目执行 运行 grails 命令

Unable to run grails command on new project on Mac due to "Could not determine java version" error

我需要在 Mac 系统上 运行 现有的 grails 项目(在 windows 上 运行ning)。

在此之前,我正在尝试设置 grails 和 运行 "hello world"。我使用 sdkman 下载并安装了 grails。我的设置目录是 -

/Users/sandeepan.nath/Desktop/setups 我在其中创建了 grails 目录和 运行 安装 grails 并创建这些的 sdk install grails 命令 -

SandeepanNath:grails sandeepan.nath$ ls -lrth
total 80
-rw-r--r--   1 sandeepan.nath  1974079253    73B Jun  1 13:03 gradle.properties
drwxr-xr-x   3 sandeepan.nath  1974079253    96B Jun  1 13:03 gradle
-rwxr--r--   1 sandeepan.nath  1974079253   4.9K Jun  1 13:03 gradlew
-rwxr--r--   1 sandeepan.nath  1974079253   2.3K Jun  1 13:03 gradlew.bat
-rwxr--r--   1 sandeepan.nath  1974079253   4.6K Jun  1 13:03 grailsw
-rwxr--r--   1 sandeepan.nath  1974079253   2.3K Jun  1 13:03 grailsw.bat
drwxr-xr-x   5 sandeepan.nath  1974079253   160B Jun  1 13:03 src
-rw-r--r--   1 sandeepan.nath  1974079253   5.3K Jun  1 13:03 grails-wrapper.jar
drwxr-xr-x  12 sandeepan.nath  1974079253   384B Jun  1 13:03 grails-app
-rw-r--r--   1 sandeepan.nath  1974079253   2.9K Jun  1 13:03 build.gradle
drwxr-xr-x   2 sandeepan.nath  1974079253    64B Jun  1 13:03 build

我 运行 grails create-app hello 在 grails 目录中创建一个项目,但它失败了 -

SandeepanNath:hello sandeepan.nath$ grails create-app hello
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/sandeepan.nath/.sdkman/candidates/grails/3.3.10/lib/org.codehaus.groovy/groovy/jars/groovy-2.4.17.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
| Error Error initializing classpath: Could not determine java version from '12.0.1'. (Use --stacktrace to see the full trace)

我向上一级,在 grails 目录之外,创建了项目(有效)-

SandeepanNath:setups sandeepan.nath$ grails create-app new_proj
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/sandeepan.nath/.sdkman/candidates/grails/3.3.10/lib/org.codehaus.groovy/groovy/jars/groovy-2.4.17.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
| Application created at /Users/sandeepan.nath/Desktop/setups/new_proj

并按照 https://docs.grails.org/3.3.10/guide/single.html#creatingAnApplication.

中的步骤创建项目

现在,当我在 new_proj 中并尝试 运行ning grails 命令时,我在这里被阻止了 -

SandeepanNath:new_proj sandeepan.nath$ grails
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/sandeepan.nath/.sdkman/candidates/grails/3.3.10/lib/org.codehaus.groovy/groovy/jars/groovy-2.4.17.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
| Error Error initializing classpath: Could not determine java version from '12.0.1'. (Use --stacktrace to see the full trace)

我在环境 PATH 变量中设置了 Java 主页 -

SandeepanNath:~ sandeepan.nath$ echo $PATH
/Users/sandeepan.nath/.sdkman/candidates/grails/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/bin:/opt/apache-maven/bin:/usr/libexec/java_home/bin:/opt/apache-maven/bin:/usr/libexec/java_home:/opt/apache-maven/bin

注意 - 没有 /usr/libexec/java_home/bin

这样的路径

不过,当我在我的项目中尝试 运行ning grails 命令时,我得到了这个 Could not determine java version 错误 -

SandeepanNath:new_proj sandeepan.nath$ grails --stacktrace
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/sandeepan.nath/.sdkman/candidates/grails/3.3.10/lib/org.codehaus.groovy/groovy/jars/groovy-2.4.17.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
| Error Error initializing classpath: Could not determine java version from '12.0.1'. (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.IllegalArgumentException: Could not determine java version from '12.0.1'.
    at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:68)
    at org.gradle.api.JavaVersion.current(JavaVersion.java:78)
    at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
    at org.gradle.tooling.internal.consumer.ConnectorServices.checkJavaVersion(ConnectorServices.java:66)
    at org.gradle.tooling.internal.consumer.ConnectorServices.close(ConnectorServices.java:53)
    at org.gradle.tooling.internal.consumer.DefaultGradleConnector.close(DefaultGradleConnector.java:57)
    at org.grails.cli.gradle.cache.CachedGradleOperation.call(CachedGradleOperation.groovy:78)
    at org.grails.cli.GrailsCli.populateContextLoader(GrailsCli.groovy:525)
    at org.grails.cli.GrailsCli.initializeProfile(GrailsCli.groovy:508)
    at org.grails.cli.GrailsCli.initializeApplication(GrailsCli.groovy:306)
    at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:269)
    at org.grails.cli.GrailsCli.main(GrailsCli.groovy:159)

从 Oracle 安装 JDK 8,安装后应该没问题。 Grails 3 需要 7 或 8 个。