This is my run configuration.
task run << {
jvmArgs "-javaagent:/home/audrius/org.springframework.instrument-3.0.5.RELEASE.jar"
jettyRun.execute()
}
but it gives me:
Could not find method jvmArgs()
How do you set javaagent for jettyRun?
You can run gradle installDist to assemble the uncompressed distribution into $buildDir/install/${project.name} .
Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.
Gradle will determine if a task is up to date by checking the inputs and outputs. For example, your compile task input is the source code. If the source code hasn't changed since the last compile, then it will check the output to make sure you haven't blown away your class files generated by the compiler.
Unfortunately, Gradle runs Jetty inside it's own JVM, so you can't set javaagent only for a specific task. It is set for the whole JVM. So, you have two ways to accomplish what you want: either you run Gradle itself with javaagent enabled, or you spawn another JVM process and run Jetty in it.
First solution is pretty easy: provide the option as you normally do. For example, put org.gradle.jvmargs = "-javaagent:/home/audrius/org.springframework.instrument-3.0.5.RELEASE.jar"
in your gradle.properties
The second way is pretty hard. You can't just spawn new JVM and say "run this Gradle task" to it. I guess you'll need to use Gradle Tooling API to spawn new process based on your exising build config via GradleConnector:
task run << {
ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File("someProjectFolder")).connect();
try {
BuildLauncher build = connection.newBuild();
build.setJvmArguments("-javaagent:/home/audrius/org.springframework.instrument-3.0.5.RELEASE.jar")
build.forTasks("jettyRun").run();
} finally {
connection.close();
}
}
As you see, second solution is pretty ugly. I'd better choose first approach.
Try with.
task run (type:JavaExec) << { ...
Because the jvmArgs is only known in a JavaExec Task.
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