简体   繁体   中英

Gradle sourceDir not adding defaultRootSource for Eclipse

I trying to configure eclipse-wtp to work with old Ant project. My web project is in /app . Everything almost works. The only missing part is tag defaultRootSource in <wb-resource deploy-path="/" source-path="/path/euro-gradle/app"/> . When I add this tag (by editing org.eclipse.wst.common.component ) applications starts normally on embedded Tomcat. Without this Tomcat just starts and not deploy application.

My gradle build:

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 ). See also http://gradle.org/docs/current/userguide/war_plugin.html . eclipse-wtp plugin will use this path as the default root source path.

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.

WbResource source code

So we have to resort to direct xml manipulation:

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'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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