playframework icon indicating copy to clipboard operation
playframework copied to clipboard

When using -Dconfig.resource=... files are not discovered in conf/ directory

Open spingel opened this issue 5 years ago • 1 comments

The play documentation on https://www.playframework.com/documentation/2.6.x/ProductionConfiguration states:

Using -Dconfig.resource This will search for an alternative configuration file in the application classpath (you usually provide these alternative configuration files into your application conf/ directory before packaging). Play will look into conf/ so you don’t have to add conf/.

Play applications created by gradle embed all conf/ files in the application jar and will only load config files from the classpath. This is not consistent with the documentation and gets even more confusing since config files are also packaged in the conf/ directory but ignored when running the application.

Looking at applications built by sbt the layout is different. Files from conf/ are not packaed inside jars but the launcher jar has a Class-Path entry in the manifest.mf that add the conf/ directory to the class path:

Class-Path: ../conf/ my-application.jar dependencies.jar...

As a work-around, the same behavior can be achieved by including the following snippet in the build file:

def classPath = tasks.createMainDistributionJar.manifest.attributes.get('Class-Path')
tasks.createMainDistributionJar.manifest.attributes([ 'Class-Path': "../conf/ ${-> classPath}"])

spingel avatar Feb 06 '20 10:02 spingel

Just a note: Play 2.8.0 had a bug where reading config.file/config.resource from devSettings and sys properties wasn't working. Fixed in Play 2.8.1. https://github.com/playframework/playframework/pull/10010

mkurz avatar Feb 06 '20 10:02 mkurz