使用 Gradle 配置嵌入式 tomcat
Configure embedded tomcat with Gradle
我试图 运行 sample app given in Spring in action(第 4 版)但无法在 build.gradle 脚本中配置 tomcat,我尝试将 tomcat 脚本中的插件 as
apply plugin: 'war'
apply plugin: 'idea'
**apply plugin: 'com.bmuschko.tomcat'**
dependencies {
compile "org.springframework:spring-webmvc:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "com.h2database:h2:$h2Version"
compile "org.hibernate:hibernate-validator:$hibernateValidatorVersion"
compile "org.apache.commons:commons-lang3:$commonsLangVersion"
compile "javax.servlet:jstl:$jstlVersion"
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
providedCompile "javax.servlet.jsp:jsp-api:$jspApiVersion"
providedCompile "javax.el:javax.el-api:$jspElVersion"
**classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2'**
**def tomcatVersion = '7.0.59'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"**
testCompile "junit:junit-dep:$junitVersion"
testCompile "org.springframework:spring-test:$springVersion"
testCompile "org.mockito:mockito-core:$mockitoVersion"
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
}
repositories {
maven { url 'http://maven.springframework.org/release' }
maven { url 'http://maven.springframework.org/milestone' }
maven { url 'http://maven.springframework.org/snapshot' }
maven { url 'http://download.java.net/maven/2' }
mavenCentral()
**jcenter()**
}
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
war {
baseName = 'spittr'
}
但是构建总是失败并给出错误:
Plugin with id 'com.bmuschko.tomcat' not found.
我已将用于 tomcat 配置的设置封装在 ** 中。
阅读 the documentation for that plugin,您需要在 gradle 构建的 buildscript
部分指定依赖项和存储库 - 这将在主构建脚本之前加载/构建。
删除文件中现有的插件和存储库,然后尝试将整个代码块添加到 gradle:
的顶部
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2'
}
}
我试图 运行 sample app given in Spring in action(第 4 版)但无法在 build.gradle 脚本中配置 tomcat,我尝试将 tomcat 脚本中的插件 as
apply plugin: 'war'
apply plugin: 'idea'
**apply plugin: 'com.bmuschko.tomcat'**
dependencies {
compile "org.springframework:spring-webmvc:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "com.h2database:h2:$h2Version"
compile "org.hibernate:hibernate-validator:$hibernateValidatorVersion"
compile "org.apache.commons:commons-lang3:$commonsLangVersion"
compile "javax.servlet:jstl:$jstlVersion"
providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
providedCompile "javax.servlet.jsp:jsp-api:$jspApiVersion"
providedCompile "javax.el:javax.el-api:$jspElVersion"
**classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2'**
**def tomcatVersion = '7.0.59'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"**
testCompile "junit:junit-dep:$junitVersion"
testCompile "org.springframework:spring-test:$springVersion"
testCompile "org.mockito:mockito-core:$mockitoVersion"
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
}
repositories {
maven { url 'http://maven.springframework.org/release' }
maven { url 'http://maven.springframework.org/milestone' }
maven { url 'http://maven.springframework.org/snapshot' }
maven { url 'http://download.java.net/maven/2' }
mavenCentral()
**jcenter()**
}
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
}
war {
baseName = 'spittr'
}
但是构建总是失败并给出错误:
Plugin with id 'com.bmuschko.tomcat' not found.
我已将用于 tomcat 配置的设置封装在 ** 中。
阅读 the documentation for that plugin,您需要在 gradle 构建的 buildscript
部分指定依赖项和存储库 - 这将在主构建脚本之前加载/构建。
删除文件中现有的插件和存储库,然后尝试将整个代码块添加到 gradle:
的顶部buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2'
}
}