gradle copy files to directory with wildcard

Viewed 1173

Gradle: copy a war to an existing tomcat

/path/tomcat-[version]/webapps

The version can be any version, and I do not want to hardcode it. Only one tomcat under the /path.

task copyWar(type: Copy) {
   from warPath
   destinationDir "/path/tomcat-*/webapps"

}

The tomcat directory does not exist during evaluation.

UPDATE

Tried:

task copyWar(type: Copy) {
   from warPath

   doFirst {
        // find tomcat directory name, set tomcatName
        destinationDir file("/path/$tomcatName/webapps")
   }

}

Gradle complains the destinationDir is not set. Obviously it is too late to set it in doFirst {} for up-to-date check.

1 Answers
Related