lapots
lapots

Reputation: 13395

gradle-tomcat-plugin `Could not create task of type 'TomcatRun'`

I've got a project with multiproject structure.

project
subproject1
subproject2
....

In my main project I add some general dependencies and in subproject I add specific dependencies.

My main project build.gradle.

apply plugin: 'eclipse'
apply plugin: 'java'

allprojects {
    group = 'com.app.pmc'
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    repositories {
        mavenCentral()
    }
    dependencies {
        testCompile 'junit:junit:4.11'
    }
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'net.saliman:gradle-liquibase-plugin:1.0.0'
        classpath 'net.saliman:groovy-liquibase-dsl:1.0.0'
        classpath 'org.postgresql:postgresql:9.3-1102-jdbc41'
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
    }
}

There is a subproject which creates web application. My build.gradle file for this project looks like this

apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'

dependencies {
    compile project(':subproject-service')

    compile 'org.springframework:spring-core:4.1.1.RELEASE'
    compile 'org.springframework:spring-context:4.1.1.RELEASE'
    compile 'org.springframework:spring-webmvc:4.1.1.RELEASE'

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

    tomcat {
        httpPort = 8080
        httpsPort = 8081
    }

}

However when I try to run gradle tR in my subproject folder - I've got an error

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\project\subproject-web\build.gradle' line: 2

* What went wrong:
A problem occurred evaluating project ':subproject-web'.
> Could not create task of type 'TomcatRun'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

What's the problem?

Upvotes: 2

Views: 1069

Answers (1)

Opal
Opal

Reputation: 84756

First of all it's invalid to define tomcat configuration closure in dependencies block. Secondly You've also an invalid dependency (loggin vs logging):

tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"

Below You can find a working script:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
    }
}

apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile 'org.springframework:spring-core:4.1.1.RELEASE'
    compile 'org.springframework:spring-context:4.1.1.RELEASE'
    compile 'org.springframework:spring-webmvc:4.1.1.RELEASE'

    def tomcatVersion = '7.0.11'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
    tomcat "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'
    }
}

tomcat {
    httpPort = 8080
    httpsPort = 8081
}

Upvotes: 2

Related Questions