The existing gretty tasks should be sufficient for many web-app development scenarios.

If you need to configure Gretty tasks, you should first look at gretty configuration - maybe, there is already everything you need.

Of course, there are cases, when you need to instantiate new gretty tasks or to extend their classes with new functions/properties. Then you need knowledge about gretty task classes.

AppStartTask

Purpose

AppStartTask starts single web-app project on a servlet-container.

Properties

Property Type Default Purpose

server-specific properties

all properties are null by default

same as server-specific properties of gretty configuration

web-app-specific properties

all properties are null by default

same as web-app specific properties of gretty configuration

interactive

boolean

true

If true, the task waits for user keypress and stops servlet-container process after it.
If false, the task does not wait for user keypress, it should be stopped by appStop task.

debug

boolean

false

If true, then servlet-container process is started debug mode: it is suspended and waits for debugger commands on port 5005.
If false, the servlet-container process is started in non-debug mode.

Property inheritance

All server-specific and web-app-specific properties of AppStartTask are set to null by default.

If, during task execution, Gretty sees that some property of AppStartTask is null, it uses the value of the property with the same name from gretty configuration. For example:

apply plugin: 'org.gretty'

gretty {
  contextPath = '/abc'
}

import org.akhikhl.gretty.AppStartTask

task('myAppRun', type: AppStartTask) {
  httpPort = 9955
}

the expected output of gradle MyAppRun is:

:myAppRun
scanInterval not specified (or zero), scanning disabled
Auto-configuring server connectors
2014-05-21 22:23:00.048 INFO  - jetty-9.1.0.v20131115
2014-05-21 22:23:01.106 INFO  - Started o.e.j.w.WebAppContext@620cc0d4{/abc,file:/home/user/Projects/testgretty/build/inplaceWebapp,AVAILABLE}
2014-05-21 22:23:01.130 INFO  - Started ServerConnector@3244630{HTTP/1.1}{0.0.0.0:9955}
Jetty server 9.1.0.v20131115 started.
: runs at the address http://localhost:9955/abc
servicePort: 9900, statusPort: 9901
Press any key to stop the jetty server.

Interpretation: we did not specify contextPath in myAppRun, so Gretty took contextPath from gretty configutation - "/abc". We specified port as 9955, so Gretty used it instead of port in gretty configuration (which is 8080 by default).

Property inheritance override

In some cases it is desirable to inhibit property inheritance within gretty tasks.

Consider the following example:

gretty {
  jvmArgs = '-Da=b'
}

task('myRun', type: AppStartTask) {
  jvmArgs = '-Dx=y'
}

as the result, myRun task will contain two parameters: '-Da=b' and '-Dx=y', but you probably wanted only '-Dx=y'.

If you want replace jvmArgs rather than append, you’ll need to call prepareServerConfig function with closure parameter:

gretty {
  jvmArgs = '-Da=b'
}

task('myRun', type: AppStartTask) {
  prepareServerConfig {
    jvmArgs = '-Dx=y'
  }
}

The closure passed to prepareServerConfig can be used for property post-processing: it is called after property merge is finished and receives merged property object as closure delegate.

There are actually two functions for property post-processing: prepareServerConfig and prepareWebAppConfig. prepareServerConfig deals with server-specific properties and prepareWebAppConfig deals with web-app-specific properties.

Task dependencies

TBD

JettyStartTask

JettyStartTask is almost identical to AppStartTask task. There’s only one difference: JettyStartTask forces Gretty to ignore the value of gretty.servletContainer and run on Jetty.

TomcatStartTask

TomcatStartTask is almost identical to AppStartTask task. There’s only one difference: TomcatStartTask forces Gretty to ignore the value of gretty.servletContainer and run on Tomcat.

AppStopTask

Purpose

AppStopTask sends "stop" command over servicePort to a single web-app, which was supposedly started by AppStartTask with interactive=false.

Properties

Property Type Default Purpose

servicePort

integer

null

same as in server-specific properties of gretty configuration

Property inheritance

AppStopTask.servicePort is set to null by default.

If, during task execution, Gretty sees that AppStopTask.servicePort is null, it uses the value of the property with the same name from gretty configuration.

Task dependencies

AppStopTask has no task dependencies.

AppRestartTask

Purpose

AppRestartTask sends "restart" command over servicePort to a single web-app, which was supposedly started by AppStartTask with interactive=false.

Properties

Property Type Default Purpose

servicePort

integer

null

same as in server-specific properties of gretty configuration

Property inheritance

AppRestartTask.servicePort is set to null by default.

If, during task execution, Gretty sees that AppRestartTask.servicePort is null, it uses the value of the property with the same name from gretty configuration.

Task dependencies

AppRestartTask has no task dependencies.

AppBeforeIntegrationTestTask

Purpose

AppBeforeIntegrationTestTask extends AppStartTask. AppBeforeIntegrationTestTask starts servlet container automatically before the designated integration test task.

By default AppBeforeIntegrationTestTask operates on the task named "integrationTest" defined in the same project. You can change this by calling integrationTestTask function:

import org.akhikhl.gretty.AppBeforeIntegrationTestTask

task('MyIntegrationTest') {
  // ...
}

task('MyBeforeIntegrationTest', type: AppBeforeIntegrationTestTask) {
  integrationTestTask 'MyIntegrationTest'
  // ...
}

Properties

Property Type Default Purpose

server-specific properties

all properties are null by default

same as server-specific properties of gretty configuration

web-app-specific properties

all properties are null by default

same as web-app specific properties of gretty configuration

interactive

boolean

true

If true, the task waits for user keypress and stops servlet-container after it.
If false, the task does not wait for user keypress, it should be stopped by appStop task.

debug

boolean

false

If true, then servlet-container is started debug mode: it is suspended and waits for debugger commands on port 5005.
If false, the servlet-container is started in non-debug mode.

integrationTestTask

String

null

Designates which gradle task is an integration task.

Property inheritance

All server-specific and web-app-specific properties of AppBeforeIntegrationTestTask are set to null by default.

If, during task execution, Gretty sees that some property of AppBeforeIntegrationTestTask is null, it uses the value of the property with the same name from gretty configuration.

Task dependencies

TBD

AppAfterIntegrationTestTask

Purpose

AppAfterIntegrationTestTask extends AppStopTask. AppAfterIntegrationTestTask stops servlet-container process automatically after the designated integration test task.

By default AppAfterIntegrationTestTask operates on the task named "integrationTest" defined in the same project. You can change this by calling integrationTestTask function:

import org.akhikhl.gretty.AppAfterIntegrationTestTask

task('MyIntegrationTest') {
  // ...
}

task('MyAfterIntegrationTest', type: AppAfterIntegrationTestTask) {
  integrationTestTask 'MyIntegrationTest'
  // ...
}

Properties

Property Type Default Purpose

servicePort

integer

null

same as in server-specific properties of gretty configuration

integrationTestTask

String

null

Designates which gradle task is an integration task.

Property inheritance

All properties of AppAfterIntegrationTestTask are set to null by default.

If, during task execution, Gretty sees that some property of AppAfterIntegrationTestTask is null, it uses the value of the property with the same name from gretty configuration.

Task dependencies

TBD