2013-08-16 50 views
3

How to change webAppDir to point to /web instead of src/main/webapp如何gradle这个

我试图改变webAppDir到的WebContent(在Eclipse动态Web应用程序结构)设置webAppDirName。

我正在使用gradle 1.7。 当我试图做同样的事情在论坛提到,它给我的错误:

Creating properties on demand (a.k.a. dynamic properties) has been deprecated 
and is scheduled to be removed in Gradle 2.0. 
Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html 
for information on the replacement for dynamic properties. 

Deprecated dynamic property: "webAppDirName" on "root project 'xxxxxxxxxx", value: "WebContent". 

输出WAR包含两个文件夹“WEB-INF”和“META-INF”

UPDATE

build.gradle

webAppDirName='WebContent' 
apply plugin: 'war' 
apply plugin: 'jetty' 
apply plugin: 'eclipse-wtp' 

sourceSets { 
    main { 
     java { 
      srcDir 'src' 
     } 
     resources { 
      srcDir 'src' 
     } 

    } 
} 
configurations { moreLibs } 

repositories { 
    flatDir { dirs "WebContent/WEB-INF/lib" } 
    mavenCentral() 
} 

dependencies { 
    compile fileTree(dir: "WebContent/WEB-INF/lib", include: '*.jar') 
    providedCompile 'javax.servlet:javax.servlet-api:3.0.1' 
    runtime 'javax.servlet:jstl:1.2' 
} 


/* Change context path (base url). otherwise defaults to name of project */ 
jettyRunWar.contextPath = '' 

请帮助。

另一个问题:

WEB-INF文件夹也在WebContent下。 WebContent的副本是否替换类文件夹。

+0

这听起来很奇怪。你可以显示导致警告消息的build.gradle文件吗? –

回答

7

终于解决了。

答案是 project.webAppDirName = 'WebContent'

的build.gradle文件:

apply plugin: 'war' 
apply plugin: 'jetty' 
apply plugin: 'eclipse-wtp' 



project.webAppDirName = 'WebContent' 

sourceSets { 
    main { 
     java { srcDir 'src' } 
     resources { srcDir 'src' } 
    } 
} 
configurations { moreLibs } 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile fileTree(dir: "WebContent/WEB-INF/lib", include: '*.jar') 
    providedCompile 'javax.servlet:javax.servlet-api:3.0.1' 
    runtime 'javax.servlet:jstl:1.2' 
} 

war { 
    exclude 'WEB-INF/lib/**' 
    exclude 'WEB-INF/classes/**' 
} 
/* Change context path (base url). otherwise defaults to name of project */ 
jettyRunWar.contextPath = ''