Distribute config files outside jar and accessible to application


(Luis Mirabal) #1

I have an application with the following structure:

application
  -> src/main
      -> java
      -> resources (config files)

Currently, the code access the config files from the classpath and when running locally is all fine.

However, we’d like to deploy a jar without the config files in it, so that we can re-run the application with different configuration parameters without having to recreate the jar.

We’re using the application plugin for this and managed to get the config files into its own directory when distributing with ./gradlew distZip using the following configuration:

applicationDistribution.from('src/main/resources') {
    into 'conf'
}

The structure of the distribution ends up like:

distributions
    -> application
        -> bin/application (start script)
        -> lib/application.jar
        -> conf/** (config files)

Which is what I’m looking for, but I also need to:

  1. Make the files in the conf directory accessible from the code (via classpath?).
  2. Also, make them higher priority than the ones included in the jar or remove them from the jar for distribution (we still want to be able to run it locally for dev purposes).

I’m not sure if the config files should live in the resources directory. For day-to-day development is quite handy but it’s now becoming a problem for deployment given that they’re automatically included in the jar.

Being able to reconfigure an application without having to re-generate its jar is a reasonable requirement but haven’t found a way of properly implementing it.