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

huangapple go评论78阅读模式
英文:

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

问题

在我开始之前:是的,Stack Overflow 上有类似的问题,但是没有一个与我的环境和设置完全相同的(大多数问题与 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 Boot 项目一样的 Maven,但是只有在添加了 Spring Data Cassandra 依赖后才会出现这个问题。

我假设在 pom 文件中添加 org.codehaus.groovy 依赖会解决这个问题,但实际上并没有起作用!

正如标题所说,我在 MacOs Catalina 上安装了 JDK 14。在任何非 Cassandra 的 Spring Boot 项目中,我的 JDK 都能够正常工作。

是不是 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>

        <!-- 其他依赖 -->

        <!-- 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>
        <!-- 构建插件等配置 -->
    </build>

</project>

这是完整的异常堆栈跟踪:

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
英文:

Before I start: YES, there are similar questions in SO about this, but not a single one have the same environment and settings as me (Most of the issues were related to gradle builds and a lot weren't even Spring related)

Furthermore, this is confusing because this only occurs when trying to use the Spring Boot's Cassandra dependency:

&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-cassandra&lt;/artifactId&gt;
&lt;/dependency&gt;

But whenever i try to start the application, I'm running with the next exception every time!

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

I don't understand why this happens because I'm not even using Gradle! I'm using Maven as in any of my Spring Boot Projects but this problem only happens whenever I add the Spring Data Cassandra Dependency.

I assumed that adding the org.codehaus.groovy dependency in the pom file would solve the problem, but still doesn't works!

As the title says, I have JDK 14 installed on MacOs Catalina. My JDK works as expected with any other dependency in any non-cassandra spring boot project.

Does spring-data-cassandra requires another dependency? Can only be used with Gradle?

I'd really appreciate if someone could give me a hand with this. I have no idea what this could be and Cassandra Support is very limited in the web.

Thanks for reading!


Here's my POM FILE:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;groupId&gt;com.cassandra&lt;/groupId&gt;
&lt;artifactId&gt;example&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;name&gt;example&lt;/name&gt;
&lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
&lt;properties&gt;
&lt;java.version&gt;11&lt;/java.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-cassandra&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
&lt;artifactId&gt;groovy-all&lt;/artifactId&gt;
&lt;version&gt;3.0.6&lt;/version&gt;
&lt;type&gt;pom&lt;/type&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

And here's the full Stacktrace of the exception:

java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.&lt;clinit&gt;(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.&lt;clinit&gt;(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.&lt;clinit&gt;(ClassInfo.java:107)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.&lt;clinit&gt;(ReflectionCache.java:39)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:209)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.&lt;init&gt;(MetaClassRegistryImpl.java:107)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.&lt;init&gt;(MetaClassRegistryImpl.java:85)
at groovy.lang.GroovySystem.&lt;clinit&gt;(GroovySystem.java:36)
at org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.&lt;init&gt;(GroovyBeanDefinitionReader.java:150)
at org.springframework.boot.BeanDefinitionLoader.&lt;init&gt;(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

答案1

得分: 6

看起来其中一个依赖项正在使用旧版本的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>
英文:

Looks like one of the dependencies is using old version of groovy. If you check the dependency tree using command :

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

you can see the dependency that requries it :

[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

A temporary solution would be to exclude those dependencies and add them with newer version :

&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-cassandra&lt;/artifactId&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
&lt;artifactId&gt;groovy&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;exclusion&gt;
&lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
&lt;artifactId&gt;groovy-json&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
&lt;artifactId&gt;groovy&lt;/artifactId&gt;
&lt;version&gt;2.5.13&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
&lt;artifactId&gt;groovy-json&lt;/artifactId&gt;
&lt;version&gt;2.5.13&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年10月26日 04:31:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/64528469.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定