JDK14-SpringBoot-Maven-Cassandra: "Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7" 异常仅与 Cassandra 依赖

JDK14-SpringBoot-Maven-Cassandra: "Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7" exception only with Cassandra dependency

开始之前:是的,SO 中也有关于此的类似问题,但没有一个具有与我相同的环境和设置(大多数问题都与 gradle 构建有关,并且很多甚至 Spring 都不相关)

此外,这令人困惑,因为这仅在尝试使用 Spring Boot 的 Cassandra 依赖项时发生:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>

但是每当我尝试启动应用程序时,我每次都是 运行 下一个异常!

java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

我不明白为什么会这样,因为我什至没有使用 Gradle!我在我的任何 Spring 引导项目中使用 Maven,但只有在我添加 Spring Data Cassandra 依赖项时才会出现此问题。

我以为在pom文件中添加org.codehaus.groovy依赖可以解决问题,但还是不行!

正如标题所说,我在 MacOs Catalina 上安装了 JDK 14。我的 JDK 与任何 non-cassandra spring 引导项目中的任何其他依赖项一起按预期工作。

spring-data-cassandra 是否需要另一个依赖项?只能与 Gradle?

一起使用

如果有人能帮我解决这个问题,我将不胜感激。我不知道这可能是什么,而且 Cassandra 支持在网络上非常有限。

感谢阅读!


这是我的 POM 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.cassandra</groupId>
    <artifactId>example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>example</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-cassandra</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>3.0.6</version>
            <type>pom</type>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>


这里是异常的完整 Stacktrace:

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.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.<init>(GroovyBeanDefinitionReader.java:150)
    at org.springframework.boot.BeanDefinitionLoader.<init>(BeanDefinitionLoader.java:85)
    at org.springframework.boot.SpringApplication.createBeanDefinitionLoader(SpringApplication.java:738)
    at org.springframework.boot.SpringApplication.load(SpringApplication.java:681)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:392)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.cassandra.example.ExampleApplication.main(ExampleApplication.java:21)
    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:564)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
2020-10-25 14:00:14.948 ERROR 5918 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

似乎依赖项之一正在使用旧版本的 groovy。如果您使用命令检查依赖关系树:

 mvn dependency:tree -Dincludes=org.codehaus.groovy

您可以看到需要它的依赖项:

[INFO] com.example:demo:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-data-cassandra:jar:2.3.4.RELEASE:compile
[INFO]    \- org.springframework.data:spring-data-cassandra:jar:3.0.4.RELEASE:compile
[INFO]       \- com.datastax.oss:java-driver-core:jar:4.6.1:compile
[INFO]          \- org.apache.tinkerpop:gremlin-driver:jar:3.4.5:compile
[INFO]             +- org.codehaus.groovy:groovy:jar:indy:2.5.7:compile
[INFO]             \- org.codehaus.groovy:groovy-json:jar:indy:2.5.7:compile

一个临时解决方案是排除这些依赖项并使用更新的版本添加它们:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-cassandra</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-json</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy</artifactId>
        <version>2.5.13</version>
</dependency>
<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-json</artifactId>
    <version>2.5.13</version>
</dependency>