简体   繁体   English

Gradle sourceDir没有为Eclipse添加defaultRootSource

[英]Gradle sourceDir not adding defaultRootSource for Eclipse

I trying to configure eclipse-wtp to work with old Ant project. 我尝试配置eclipse-wtp以使用旧的Ant项目。 My web project is in /app . 我的网络项目在/app Everything almost works. 一切都差不多了。 The only missing part is tag defaultRootSource in <wb-resource deploy-path="/" source-path="/path/euro-gradle/app"/> . 唯一缺少的部分是<wb-resource deploy-path="/" source-path="/path/euro-gradle/app"/>标签defaultRootSource When I add this tag (by editing org.eclipse.wst.common.component ) applications starts normally on embedded Tomcat. 当我添加此标记(通过编辑org.eclipse.wst.common.component )时,应用程序通常在嵌入式Tomcat上启动。 Without this Tomcat just starts and not deploy application. 没有这个Tomcat只是启动而不是部署应用程序。

My gradle build: 我的gradle构建:

eclipse {
    wtp {
        facet{
            facet name: 'jst.web', version: '2.5'
            facet name: 'java', version: '1.7'
        }

        component {
            contextPath = '/'
//            resource deployPath: '/', sourcePath: '/app'
            sourceDirs += file('/app')
        }
    }
}

What you need is to set webAppDirName on your project (which defaults to src/main/webapp ). 您需要的是在项目上设置webAppDirName (默认为src/main/webapp )。 See also http://gradle.org/docs/current/userguide/war_plugin.html . 另见http://gradle.org/docs/current/userguide/war_plugin.html eclipse-wtp plugin will use this path as the default root source path. eclipse-wtp插件将使用此路径作为默认根源路径。

Unfortunately, it doesn't appear that the Gradle WbResource generator, used to create the deployment configuration file .settings/org.eclipse.wst.common.component, supports anything but deploy path and source path at the moment. 不幸的是,用于创建部署配置文件.settings / org.eclipse.wst.common.component的Gradle WbResource生成器似乎不支持除了部署路径和源路径之外的任何内容。

WbResource source code WbResource源代码

So we have to resort to direct xml manipulation: 所以我们必须采用直接的xml操作:

eclipse.wtp.component.file.withXml { provider ->
    def mainWebSourcePathNode = provider.asNode()['wb-module'][0].get('wb-resource').find { 
        it.attribute('source-path') == project.convention.plugins.war.webAppDirName 
    }
    mainWebSourcePathNode['@tag'] = 'defaultRootSource'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM