Question

I'm used to mvn, but I'm testing Gradle (v1.8) for a small web development project.

I've noticed that the Jetty Gradle plugin support autoscan and hot deployment, so I've enabled it. My goal is to recompile from Eclipse and get a Jetty reload the context every time I change a Controller, etc.

However, this is non working, mainly because Gradle compilation output goes to build/, however the Gradle Eclipse plugin creates a .classpath configuration that directs all the Eclipse output to /bin (even mixing test and main source folders).

Is there a way to?...

  1. Run graddle jettyRun on a separate console.
  2. Save a modified class on Eclipse (triggering a compilation)
  3. See that Jetty picks up the change and reloads the context.

As per my research, I've identified three workarounds, but none of them solves the question above (I'm posting them in case you have related comments or more recommendations)

  1. Tweak Gradle Eclipse config to direct test and main build output to the same directory that Gradle uses (using the pattern seen here). This is not recommended by some people, as it means using two different compilation systems that could interfere with each other.
  2. Use the Gradle eclipse-wtp plugin to generate a WTP2 config, and use Eclipse's "Run AS -> Run on Server". This accomplishes the hot deployment / iterative goal and keeps both systems (IDE and Gradle) isolated. However, you need to setup the server on Eclipse.
  3. (Not really a workaround): I've tested Spring's Eclipse build (STS) Gradle integration, however it seems that the integration is focused on the project setup, and while Gradle builds can be automatically triggered, Eclipse compilation is still redirected to bin/.
Was it helpful?

Solution

So you are interested in fine-tuning hot-deployment, right?

Please, consider using Gretty gradle plugin: https://github.com/akhikhl/gretty

It is an advanced gradle plugin for running web-apps on jetty. It does exactly what you want, regarding hot-deployment (and, possibly, even more).

Disclosure: I am author of Gretty plugin.

OTHER TIPS

If you don't want to change to other plugins, here are two steps for the workaround:

  1. add below configurations into your build.gradle: jettyRun { reload = "automatic" scanIntervalSeconds = 1 }

  2. each time after you changed java code, run the following task: gradle compileJava

Because jetty is watching the *.class files, it will hot reload only after *.class files changed.

Refer to this link: https://discuss.gradle.org/t/hot-deploy-with-jetty-plugins-jettyrun/7416

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top