I have a little java project with standard directory set: ‘src/main/java’, ‘src/test/java’. I use Application plugin for make a distribution of the project and this distribution must have some configuration files, that lies IN classpath, but NOT in resources to give users an ability to change it.
Ok, for this feature I use ‘src/dist’ directory, from which all files copy to build/install/ (%APP_HOME%). I placed ‘config’ catalog to ‘src/dist’ and set ‘classpath’ of startScripts:
startScripts {
classpath += files('src/dist/config')
}
Resulting directory is %APP_HOME%/config, but CLASSPATH in a launch script is %APP_HOME%/lib/config. Only function of scartScripts.classpath is configuring of launch script’s CLASSPATH and this function is not performed correctly.
It happens because of classpath calculating algorithm:
- ApplicationPlugin sets default classpath in the next way:
startScripts.classpath = project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime
- Then ‘…/task/application/CreateStartScript.groovy’ (that is used only from ApplicationPlugin.groovy) makes next step:
generator.classpath = getClasspath().collect { "lib/${it.name}" }
It configure resulting classpath and always add ‘lib/’.
I think it would be better to change a logic of classpath configuring: 1) ApplicationPlugin knows target pathes and build classpath fully itself. 2) ApplicationPlugin must build resulting classpath more smarty because it knows where to copy. 3) So, finally, in CreateStartScript.groovy
generator.classpath = getClasspath()
I think it’s not good that CreateStartScript makes some hidden work to final configure of classpath
If my way of thinking is right I can try to contribute to Groovy. Because my final scripts is look like this (it’s worked):
startScripts {
classpath += files('src/dist/config')
doLast {
def windowsScriptFile = file getWindowsScript()
def unixScriptFile
= file getUnixScript()
windowsScriptFile.text = windowsScriptFile.text.replace('%APP_HOME%\lib\config', '%APP_HOME%\config')
unixScriptFile.text
= unixScriptFile.text.replace('$APP_HOME/lib/config', '$APP_HOME/config')
}
}