Gradle tomcat plugin and properties files

2019-02-27 17:42发布

问题:

I would like to use the gradle tomcat plugin in order to do integration tests with gradle. The current project relies on some .properties files underneath the running tomcat's catalina.base directory (cannot be changed because another dependent project relies on them as well).

Does anybody know how to deploy those files to the embedded tomcat instance?

回答1:

I figured out it's just a simple copy task issue. Here's my solution:

task copyDMConfigFiles << {
def srcDir = new File('src/test/resources/conf')
if(!srcDir.isDirectory())
    println "Outlet configuration files missing!!!"

def buildDir = new File('build/tmp/tomcatRunWar/conf')
if(!buildDir.isDirectory()) {
    println "Outlet target directory missing. Creating one"
    buildDir.mkdirs()
}

copy {
    from(srcDir)
    into(buildDir)
    include '**/*.properties'
    include '**/*.xml'
}

copy {
    from('src/main/webapp/WEB-INF')
    into('build/tmp/tomcatRunWar/work/Tomcat/localhost/digitalmedia/WEB-INF')
    include 'web.xml'
    include 'dispatcherservlet.xml'
}

}