- Open the gradle.build file and add the buildScript() function that accepts a closure containing all libraries needed to be referenced in classpath. At this step, we need to import gradle-tomcat-plugin under the group com.bmuschko:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
}
}
- Add the following libraries to the classpath:
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'com.bmuschko.tomcat-base'
- (Optional) Add the following Tomcat 9.0 libraries that enable Gradle to run embedded Tomcat through the tomcatRun() and tomatRunWar() functions:
dependencies {
def tomcatVersion = '9.0.0.M9'
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'
}
}
- (Optional) Configure Tomcat 9 details through the tomcat() function:
tomcat {
httpsPort = 8443
enableSSL = true
users {
user {
username = 'packt'
password = 'packt'
roles = ['manager-gui', 'manager-script']
}
}
}
- To deploy the project into the installed Tomcat 9, create a Gradle task deploy that copies the WAR file to the /webapp folder:
task deploy (dependsOn: war){
copy {
from "build/libs"
into
"C:\MyFiles\Development\Servers\Tomcat9.0\webapps"
include "*.war"
}
}
- You can now run deploy in the Gradle Task Launcher.