Gradle Application Plugin : How can I run jvm application with -javaagent options?
aspectj, gradle, javaagents, jvm
Solution
Yep, that's done like this:
project(':whatever') {
apply plugin: 'application'
mainClassName = 'some.Main'
repositories { mavenCentral() }
dependencies {
// substitute needed version of aspectj
runtime "org.aspectj:aspectjweaver:$aspectj"
}
applicationDefaultJvmArgs = [
"-javaagent:\$APP_HOME/lib/aspectjweaver-${aspectj}.jar"
]
// $ symbol gets escaped in script anyway:( so we need to replace it.
startScripts {
doLast {
unixScript.text = unixScript.text.replace('\\$APP_HOME', '\$APP_HOME')
// do something like this for Windows scripts also
}
}
}
Problem
I use application plugin in gradle (v1.10) to package and to run my apps. So, now I need to use aspects (aspectj), and I dont want to use aspectj-compiler (ajc). Is it possible to tweak gradle application run scripts, so my app could be run with load-time-weaving? Something like providing jvm options: -javaagent:_path_to_aspectj_weaver.jar