How do I pass a link to the distribution home directory using a Gradle app plugin?

I am using the Gradle app plugin and I want to create a distro containing a conf directory inside the app home folder. This directory should contain multiple configuration files. like java.util.logging etc. To point the JUL to my config file, I have to pass in a jvm property -Djava.util.logging.config=...

, and here I need a reference to the application's installation directory. The scripts seem to set this path in the APP_HOME variable . But there is a problem: I cannot pass the defaultJvmOpts property something like $APP_HOME

, since there are two types of scripts (win and nix) and furthermore, the dollar sign is unconditionally escaped.

So, is there a way to pass a reference to the application's home directory as an argument to the virtual machine?

+3


source to share


1 answer


Luke Daly posted an answer to a question on the Gradle forum: http://forums.gradle.org/gradle/topics/how_to_pass_a_reference_to_distribution_home_directory_using_application_plugin :

You will need to increase the startup scripts.

Here's an example of this here: https://github.com/ratpack/ratpack/blob/master/ratpack-gradle/src/main/groovy/ratpack/gradle/RatpackPlugin.groovy#L93

Thanks for his help.



So, I added the following code to the end of mine build.gradle

:

CreateStartScripts startScripts = project.startScripts
startScripts.with {
    doLast {
        unixScript.text = unixScript.text.replaceFirst('(?<=DEFAULT_JVM_OPTS=)((\'|\")(.*)(\'|"))(?=\n)',
                '\'$3 "-Dtcproxy.config.url=file:\\$APP_HOME/conf/proxy.properties"\'')
        windowsScript.text = windowsScript.text.replaceFirst('(?<=DEFAULT_JVM_OPTS=)(.*)(?=\r\n)',
                '$1 "-Dtcproxy.config.url=file:%~dp0../conf/proxy.properties"')
    }
}

      

And it works! Hopefully later, this functionality will be added to the plugin.

0


source







All Articles