4

I'm using a Gradle application plugin and I want to create distribution which contains conf directory inside app home folder. This dir should contain several configuration files. e.g. java.util.logging properties, etc. To point JUL my configuration file I should pass jvm property -Djava.util.logging.config=... and here I need a reference to app installation directory. It seems that scripts set this path into APP_HOME variable. But there is a problem: I cannot pass into defaultJvmOpts property something like $APP_HOME since there are two kinds of scripts (win and nix) and moreover dollar sign is unconditionally escaped.

So, is there any way to pass a reference to app home directory as a virtual machine argument?

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
viator
  • 1,241
  • 3
  • 13
  • 23

1 Answers1

1

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

You'll have to augment the start scripts.

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

Thanks to him for help.

So, I added the following code to the end of my 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! Hope later such functionality will be added to the plugin.

viator
  • 1,241
  • 3
  • 13
  • 23