Could you please share a build.gradle script example with configured folder "conf":
- This folder including all containing files is packaged into zip file during "gradle distZip";
- Files in this folder are on classpath (e.g. accessible to ClassLoader) in startscripts files (in bin folder);
- These files also are on classpath when running gradle run, gradle build etc.
Addition #1:
I've done actions mentioned in answer pointed by @wakjah, files was copied to a zip file and was not put into jar during gradle distZip
, this covers my requirement #1. But this folder is not on classpath in start scripts from bin
folder (requirement #2 is not covered). Files are not on classpath when running gradle clean run
(requirement #3 is not covered).
Addition #2:
I started sample project from scratch and with the help of @wakjah now I have:
- Req #1: ok (directory
config
contains resource file), but this resource is also inlib
folder. - Req #2: ok (directory
config
is on classpath in start script), but classpath additionally contains invalid folder%APP_HOME%\lib\config
- Req #3: ok
Additionally, I tested 3 approaches of loading file contents (as mentioned here), method Thread.currentThread().getContextClassLoader().getResource(name)
succeeded.
Added my sample project zip file here: http://rgho.st/8r2dJjSz7
Addition #3:
When I comment / remove in gradle script:
dependencies {
runtime files('src/dist/config')
}
lib/config
folder is not on CLASSPATH (it's ok), and resource file gets not copied to lib
folder (it's ok). But resource file is failed to load both starting class main() method from Idea and running gradle clean run
from command prompt. After gradle clean distZip
and deploying (unpacking) application, resource gets loaded.
Addition #4:
After replacing
dependencies {
runtime files('src/dist/config')
}
to
tasks.withType(JavaExec) {
classpath += files('src/dist/config')
}
everything went fine, thanks, @wakjah!
There is one more issue, not mentioned in initial requirements: when I start this project inside Idea (not executing gradle run, but starting main() in class directly from Idea), file in config
directory could not be loaded using any of approaches mentioned earlier.