craig.schneider
craig.schneider

Reputation: 145

Spring Boot Gradle Tomcat 8

The Spring Boot reference guide provides instructions for upgrading to Tomcat 8 by setting a custom property in Maven:

<properties>
  <tomcat.version>8.0.3</tomcat.version>
</properties>

What is the equivalent way to do the same in a Gradle build?

I have tried the following to no avail. It stays on version 7.0.52 at app startup.

buildscript {
  ...    
  ext['tomcat.version'] = '8.0.3'
  ...
}

Upvotes: 9

Views: 7534

Answers (4)

turgos
turgos

Reputation: 1614

This is how I could configure Spring Boot1.3.3 to work with Tomcat v8.0.33. By default it works with version 8.0.32 and that version has the Websocket problem.

  compile("org.springframework.boot:spring-boot-starter-web") {
    exclude module: "spring-boot-starter-tomcat"
  }
  //providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
  compile 'org.apache.tomcat.embed:tomcat-embed-core:8.0.33'
  compile 'org.apache.tomcat.embed:tomcat-embed-el:8.0.33'
  compile 'org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.33'
  compile 'org.apache.tomcat.embed:tomcat-embed-websocket:8.0.33'

Upvotes: 0

sandris
sandris

Reputation: 1538

For setting up version of tomcat I used:

    dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") {
        exclude module: "spring-boot-starter-tomcat"
    }
    compile 'org.springframework.boot:spring-boot-starter-tomcat:1.1.8.RELEASE'
}

where you just need to find which spring-boot-starter-tomcat suits your needs

Upvotes: 0

akhikhl
akhikhl

Reputation: 2578

Please, have a look at Gretty plugin: it supports Tomcat 8 (as well as Tomcat 7, Jetty 7/8/9) and SpringBoot out of the box. No dependency tweaking is needed.

https://github.com/akhikhl/gretty

Disclosure: I am author of Gretty plugin.

Upvotes: 3

Dave Syer
Dave Syer

Reputation: 58094

Gradle has no equivalent of a "parent pom", so you have to call out the dependency explicitly. Because it's groovy you can probably do it programmatically, something like:

configurations.all {
  resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    if (details.requested.group == 'org.apache.tomcat.embed') {
        details.useVersion '8.0.3'
    }
  }
}  

We could add some support for version properties to the Spring Boot Gradle plugin (feel free to open an issue in github) but it would probably have to be optional.

Upvotes: 5

Related Questions