Let’s assume, you are developing web-applications with JVM-based languages and technologies and are looking for the solution of the following problem:
You have a bunch of web-apps, that must run all at the same time, because they call each other. You also want to debug multiple web-apps and even run integration tests – on the complete bunch.
Here is the solution to this problem: use Gretty. This is gradle plugin, capable of exactly this: running multiple web-apps, debugging, integration tests. Of course, it is open-source and available at jcenter and maven central.
Gretty can start arbitrary number of web-apps of various types: gradle projects, WAR-files in the file system and even WAR-files from maven dependencies.
Multiple web-apps feature works out-of-the-box in configureless mode, although it is fully configurable/customizable.
The central concept of Multiple web-apps feature is farm – a collection of web-apps, that should run together.
There are two ways to define and use farms:
- Default farm is automatically created for you by Gretty. You may add artbitrary web-apps to it and then invoke farm-specific tasks: farmRun, farmRunDebug, etc. Note that farm-specific tasks are not using gretty tasks (jettyRun, jettyRunDebug, etc.), but they understand and use gretty configurations.
- Named farms, which you create yourself in gradle script. You can add as many named farms as you want, and you can add web-apps to farms in arbitrary constellations. Each named farm provides a specific set of farm tasks. For example, if you define farm with name “XYZ”, there will be new tasks farmRunXYZ, farmRunDebugXYZ, etc. available.
You can start using multiple web-apps support right away, using the following scenario as a starting point:
Create three empty folders: ProjectA, ProjectB and ProjectC, so that folder tree looks like this:
Create file “ProjectA/settings.gradle”, insert code:
include 'ProjectA', 'ProjectB'
Explanation: we organize multi-project setup, so that multiple web-apps can be started/stopped by gretty-farm plugin.
Create file “ProjectA/build.gradle”, insert code:
apply plugin: 'gretty-farm'
Create file “ProjectA/ProjectB/build.gradle”, insert code:
apply plugin: 'gretty'
Create file “ProjectA/ProjectC/build.gradle”, insert code:
apply plugin: 'gretty'
Done! Now you can run multiple web-apps by running the following command in ProjectA:
Jetty server 9.1.0.v20131115 started.
:ProjectB runs at the address http://localhost:8080/ProjectB
:ProjectC runs at the address http://localhost:8080/ProjectC
servicePort: 9900, statusPort: 9901
Press any key to stop the jetty server.
Of course, you’ll get 404 in the browser, because web-apps don’t contain any pages. But, as soon as you add pages or/and servlets to the web-apps, things will get real.
By default farm automatically adds all subprojects of the farm project, which are facilitated with gretty plugin, to web-apps list. You can also explicitly add web-apps to the given farm.
Gretty-farm plugin defines new, distinct set of tasks for running farms: farmRun, farmRunDebug, farmRunWar, farmRunWarDebug, etc.