apply plugin: 'org.akhikhl.gretty'
gretty {
contextPath = '/abc'
}
import org.akhikhl.gretty.AppStartTask
task('myAppRun', type: AppStartTask) {
port = 9955
}
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.
Property | Type | Default | Purpose |
---|---|---|---|
server-specific properties |
all properties are null by default |
||
web-app-specific properties |
all properties are null by default |
||
interactive |
boolean |
true |
If true, the task waits for user keypress and stops servlet-container process after it. |
debug |
boolean |
false |
If true, then servlet-container process is started debug mode: it is suspended and waits for debugger commands on port 5005. |
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.akhikhl.gretty'
gretty {
contextPath = '/abc'
}
import org.akhikhl.gretty.AppStartTask
task('myAppRun', type: AppStartTask) {
port = 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).
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.
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 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 sends "stop" command over servicePort to a single web-app, which was supposedly started by AppStartTask with interactive=false.
Property | Type | Default | Purpose |
---|---|---|---|
servicePort |
integer |
null |
same as in server-specific properties of gretty configuration |
AppRestartTask sends "restart" command over servicePort to a single web-app, which was supposedly started by AppStartTask with interactive=false.
Property | Type | Default | Purpose |
---|---|---|---|
servicePort |
integer |
null |
same as in server-specific properties of gretty configuration |
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'
// ...
}
Property | Type | Default | Purpose |
---|---|---|---|
server-specific properties |
all properties are null by default |
||
web-app-specific properties |
all properties are null by default |
||
interactive |
boolean |
true |
If true, the task waits for user keypress and stops servlet-container after it. |
debug |
boolean |
false |
If true, then servlet-container is started debug mode: it is suspended and waits for debugger commands on port 5005. |
integrationTestTask |
String |
null |
Designates which gradle task is an integration task. |
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.
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'
// ...
}
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. |