I have a Java application that needs to read config files from somewhere on the classpath, outside of the .jar files and lib directory. The config directory is shared between projects, so I create a symlink to the shared directory from build/install/app/config. My build file is something like this:
apply plugin: 'java'
apply plugin: 'application'
dependencies {
runtime files("$rootDir/../config")
}
installDist << {
def link = Paths.get("$buildDir/install/$applicationName/config")
def target = Paths.get("$rootDir/../config").normalize()
Files.createSymbolicLink link, target
}
startScripts {
// http://stackoverflow.com/a/18712556/320036
doLast {
def unixScriptFile = file getUnixScript()
unixScriptFile.text = unixScriptFile.text.replaceFirst(
/APP_HOME\/lib\/config(:|$)/,
'APP_HOME/config$1')
}
}
There are two problems:
-
The resulting
app/lib/directory contains the config files, because of theruntimedependency. They are not on the classpath so they’re ignored, but how can I exclude them? I tried doing this:applicationDistribution.with { exclude('config/**') }But it doesn’t work. Indeed, even
exclude('**')doesn’t seem to exclude anything. -
The
distZiptask doesn’t include theconfigdirectory. Although I want it to be a symlink when I build withinstallDist, I’d like it to be copied into the zip file when usingdistZip.
Maybe I’m just going about this in entirely the wrong way?
Full build files can be found here:
