gpt4 book ai didi

gradle - 在 Gradle 构建中启动 Gretty 时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-12-03 06:11:46 27 4
gpt4 key购买 nike

当我尝试使用 gradle appRun 启动 Gretty 时和 Gradle 2.9我收到以下错误。

Exception in thread "main" java.lang.NoClassDefFoundError: groovy/json/JsonSlurper
at org.akhikhl.gretty.Runner.run(Runner.groovy:114)
at org.akhikhl.gretty.Runner.this$2$run(Runner.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.akhikhl.gretty.Runner.main(Runner.groovy:46)
Caused by: java.lang.ClassNotFoundException: groovy.json.JsonSlurper
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 12 more
Exception in thread "Thread-3" org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:367)
at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:31)
at org.gradle.api.internal.file.DefaultFileOperations.javaexec(DefaultFileOperations.java:159)
at org.gradle.api.internal.project.AbstractProject.javaexec(AbstractProject.java:792)
at org.gradle.api.internal.project.AbstractProject.javaexec(AbstractProject.java:788)
at org.gradle.api.Project$javaexec$10.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at org.akhikhl.gretty.DefaultLauncher.javaExec(DefaultLauncher.groovy:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at org.akhikhl.gretty.LauncherBase$_launchThread_closure4.doCall(LauncherBase.groovy:240)
at org.akhikhl.gretty.LauncherBase$_launchThread_closure4.doCall(LauncherBase.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:420)
at groovy.lang.Closure.run(Closure.java:507)
at java.lang.Thread.run(Thread.java:745)

我的申请不需要 groovy-json根本没有,我怀疑 Gretty Gradle 插件需要它,但我找不到问题。这是我尝试过的:

申请 gretty.plugin从本地位置并添加 groovy-json作为构建脚本的类路径依赖项。
buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'org.akhikhl.gretty:gretty:1.2.4'
classpath "org.codehaus.groovy:groovy-json:${groovyVersion}"
}
}

repositories {
jcenter()
}

dependencies {
// does not affect the situation either
runtime "org.codehaus.groovy:groovy-json:${groovyVersion}"
}

if (!project.plugins.findPlugin(org.akhikhl.gretty.GrettyPlugin))
project.apply(plugin: org.akhikhl.gretty.GrettyPlugin)

无论我使用 Jetty 9 还是 Tomcat 8,它都不会改变。它总是会导致相同的错误。

我找到了这种行为的原因。

在我的构建脚本中,我确保 groovy-all永远不会被使用并被 groovy 取代模块(见下文)。
configurations.all {
resolutionStrategy {

eachDependency { DependencyResolveDetails details ->
//changing 'groovy-all' into 'groovy':
if (details.requested.name == 'groovy-all') {
details.useTarget group: details.requested.group, name: 'groovy', version: groovyVersion
}
}
}

所以这就是错误发生的原因。但是谁能告诉我为什么我在添加 groovy-json 时没有得到修复如 runtime依赖?

最佳答案

我遇到了同样的问题。还没有完全解决它,但这似乎有帮助:

  • https://github.com/akhikhl/gretty/issues/5
  • https://github.com/akhikhl/gretty/issues/72

  • 本质上说的是 grettyplugin 本身的 deps 必须添加关键字 gretty (不是编译也不是运行时)
    compile group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'

    runtime group: 'org.postgresql', name: 'postgresql', version: '9.4.1209.jre7'

    gretty 'com.atomikos:transactions-jta:4.0.4'

    希望这对其他人有所帮助(我花了很长时间才弄清楚)。

    关于gradle - 在 Gradle 构建中启动 Gretty 时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34103234/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com