无法创建类型' TomcatRun'

时间:2014-11-25 15:22:31

标签: intellij-idea gradle gradle-tomcat-plugin

也许有人可以帮忙配置gradle-tomcat-plugin?

这是 build.gradle 的内容:

buildscript {
    ext {
        springBootVersion = '1.1.9.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'war'
apply plugin: 'spring-boot'
apply plugin: 'com.bmuschko.tomcat'

sourceCompatibility = 1.6
version = '1.0'

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    def tomcatVersion = '7.0.42'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
        exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
    }
}

运行任务tomcatRun时出现此错误:无法创建“TomcatRun”类型的任务。这个结果:

Caused by: java.lang.NoClassDefFoundError: org/codehaus/groovy/runtime/typehandling/ShortTypeHandling
        at com.bmuschko.gradle.tomcat.tasks.Tomcat.<init>(Tomcat.groovy:28)
        at com.bmuschko.gradle.tomcat.tasks.AbstractTomcatRun.<init>(AbstractTomcatRun.groovy)
        at com.bmuschko.gradle.tomcat.tasks.TomcatRun.<init>(TomcatRun.groovy)
        at com.bmuschko.gradle.tomcat.tasks.TomcatRun_Decorated.<init>(Unknown Source)
        at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:62)
        at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
        at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:124)

2 个答案:

答案 0 :(得分:0)

如果有人遇到同样的问题,你可能正在使用 gradle 而不是 gradle wrapper 。我通过运行gradlew tomcatRun任务来解决问题。

答案 1 :(得分:0)

您需要至少将Gradle更新到2.1版才能使其正常工作。