I'm using Gradle's Application plugin to generate the install for a standalone java application. I have a configuration file I need to put on the classpath but I can't seem to get it to generate the classpath correctly in the sh/bat files. This configuration file needs to be located outside of the jar.
The conf file is in the directory /src/dist/conf/
so when I run installApp
it installs it under a conf directory like this $APP_HOME/conf
.
I tried adding this directory to the claspath like this:
startScripts.classpath.add(files('$APP_HOME/conf'))
but when I look at the classpath in the sh/bat files it adds an entry that looks like this:
$APP_HOME/lib/conf
How do I tell gradle to drop the lib
section for this entry?
Gradle dependencies are grouped into sets called configurations. Different configurations are used for building classpath for the major two tasks — compile classpath is used for compilation and runtime classpath is used for running the application.
You can run gradle installDist to assemble the uncompressed distribution into $buildDir/install/${project.name} .
The Application plugin facilitates creating an executable JVM application. It makes it easy to start the application locally during development, and to package the application as a TAR and/or ZIP including operating system specific start scripts.
Applying Plugins There are two types of plugins one is script plugin and second is binary plugin.
Another workaround for this issue (GRADLE-2333) is proposed by Alexandr Fadeev here.
Here is (a bit modified) Alexandr's solution that solved the problem for me on Gradle-1.6:
startScripts { classpath += files('src/dist/XxxAPlaceHolderForAConfigxxX') doLast { def windowsScriptFile = file getWindowsScript() def unixScriptFile = file getUnixScript() windowsScriptFile.text = windowsScriptFile.text.replace('%APP_HOME%\\lib\\XxxAPlaceHolderForAConfigxxX', '%APP_HOME%\\config') unixScriptFile.text = unixScriptFile.text.replace('$APP_HOME/lib/XxxAPlaceHolderForAConfigxxX', '$APP_HOME/config') } }
It's a bit uglier than Josh's solution, but it allows you to preserve the exact directory layout (/src/dist/conf and $APP_HOME/conf) mentioned in the original question.
The easiest way to get a file onto the class path is to put it into src/main/resources
. src/dist
is for adding files to the distribution (i.e. zip file), not to the Jar/class path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With