How can I use outsourced configuration files with the Tomcat Gradle plugin?


Problem. I have various environment-specific configuration files that I want to include on the classpath at runtime, but I don't want these to be part of the WAR itself. For example, I have a log4j.xml file for the dev environment with debugging turned on, and a properties file with lots of environment-specific credentials, endpoints and so forth.

I want these outside the WAR because I want to release the same WAR I test, rather than building separate environment-specific WARs. I could potentially include multiple environment-specific sets of configuration in the WAR (similar to the profile capability that both Maven and Spring provide), but I prefer not to.

Standalone Tomcat has the shared.loader feature (in, and Jetty has extraClasspath, but I don't know how to do this with the Gradle Tomcat plugin. Is there a way?

Related posts. The following posts are related, but they seem to involve copying the configuration files into locations that end up being pulled into the WAR file.

  • Gradle tomcat plugin and properties files
  • How do I add a .properties file into my WAR using gradle?

Figured out a way to do this:

buildscript {
    repositories { mavenCentral() }
    dependencies {
        classpath "org.gradle.api.plugins:gradle-tomcat-plugin:0.9.7"
        classpath files("/path/to/config/files")