赞
踩
在一个web项目中,用到了jetty,在用gradle构建项目时发现提示 Plugin with id 'jetty' not found.即找不到这个插件。
Groovy代码如下:
- apply plugin: 'java'
- apply plugin: 'war'
- apply plugin: 'jetty'
-
- repositories {
- mavenCentral()
- }
-
- dependencies {
- providedCompile 'javax.servlet:servlet-api:2.5',
- 'javax.servlet.jsp:jsp-api:2.1'
- runtime 'javax.servlet:jstl:1.1.2',
- 'taglibs:standard:1.1.2'
- }
提示如下
FAILURE: Build failed with an exception.
* Where:
Build file 'H:\gradleCode\test\build.gradle' line: 3
* What went wrong:
A problem occurred evaluating root project 'test'.
> Plugin with id 'jetty' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option
to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
去官网看了下,发现了个帖子https://discuss.gradle.org/t/gradle2-still-cant-specify-jetty-version/5069
说的是在Gradle 1.x 中jetty不能指定特定的版本,可我这的提示是根本找不到这个插件,我就很迷。。。。
帖子有人说推荐第三方库gretty 我尝试了一下,成功了
如果你用的Gradle是2.1版本以上的,就这几行代码就可以了
- plugins {
- id "org.akhikhl.gretty" version "2.0.0"
- }
否则就要写多几行:
- buildscript {
- repositories {
- maven {
- url "https://plugins.gradle.org/m2/"
- }
- }
- dependencies {
- classpath "gradle.plugin.org.akhikhl.gretty:gretty:2.0.0"
- }
- }
-
- apply plugin: "org.akhikhl.gretty"
这是我的build.gradle:
- apply plugin: 'java'
- apply plugin: 'war'
- buildscript {
- repositories {
- maven {
- url "https://plugins.gradle.org/m2/"
- }
- }
- dependencies {
- classpath "gradle.plugin.org.akhikhl.gretty:gretty:2.0.0"
- }
- }
-
- apply plugin: "org.akhikhl.gretty"
- repositories {
- jcenter()
- }
-
- dependencies {
- providedCompile 'javax.servlet:servlet-api:2.5',
- 'javax.servlet.jsp:jsp-api:2.1'
- runtime 'javax.servlet:jstl:1.1.2',
- 'taglibs:standard:1.1.2'
- }
运行结果如下:
gradle build
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。