使用Gradle配置嵌入式tomcat(Configure embedded tomcat with Gradle)

编程入门 行业动态 更新时间:2024-10-25 00:23:48
使用Gradle配置嵌入式tomcat(Configure embedded tomcat with Gradle)

我试图在Spring中运行示例应用程序 (第4版),但无法在build.gradle脚本中配置tomcat,我尝试将tomcat插件添加到脚本中

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配置的设置。

I was trying to run sample app given in Spring in action(4th edition) but not able to configure tomcat with in build.gradle script,I have try to put the tomcat plugin with in script 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' }

But it always fails build giving error:

Plugin with id 'com.bmuschko.tomcat' not found.

I have encapsulate settings in ** that I have used for tomcat configuration.

最满意答案

阅读该插件的文档 ,您需要在gradle构建的buildscript部分中指定依赖项和存储库 - 这将在主构建脚本之前加载/构建。

删除当前在文件中包含它们的插件和存储库,并尝试将整个代码块添加到gradle的顶部:

buildscript { repositories { jcenter() } dependencies { classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2' } }

Reading the documentation for that plugin, you need to specify the dependency and the repository in the buildscript section of your gradle build - this will be loaded / built before the main build script.

Remove the plugin and repository as you currently have them in the file, and try adding this whole block of code to the top of your gradle:

buildscript { repositories { jcenter() } dependencies { classpath 'com.bmuschko:gradle-tomcat-plugin:2.2.2' } }

更多推荐

本文发布于:2023-08-07 05:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1461572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌入式   Gradle   tomcat   embedded   Configure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!