Dropwizard Project Template

At bloomhealth we use dropwizard to build small, fast web services. Recently I’ve been contributing to Peter Ledbrook’s lazybones project templating system and I finally made time to build a template for dropwizard.

The template creates a default directory structure, an empty service implementation and a gradle build. There are some custom gradle tasks for running migrations and starting the service. It includes dependencies for testing with spock as well. You can see the template on github.

You can install lazybones via gvm. If you’re not using gvm, then you should start.

1
2
gvm install lazybones
lazybones create dropwizard 0.1 ~/my-dropwizard-project

Lazybones will prompt you for some information to build the template with.

1
2
3
4
Define value for 'group': org.kyleboon
Define value for 'version' [0.1]: 0.1
Define value for package structure: org.kyleboon.contact
Define value for the name of the service: Contact

After that it will display the README for the template and tell you the project has been created.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Filtering file /Users/kboon/temp/gradle.properties
Filtering file
/Users/kboon/temp/src/main/groovy/packageName/ServiceNameService.groovy
Filtering file
/Users/kboon/temp/src/main/groovy/packageName/ServiceNameConfiguration.groovy
     [move] Moving 2 files to
/Users/kboon/temp/src/main/groovy/org/kyleboon/contact

# Introduction

You have created an dropwizard application using lazybones. The
application will start but it has no resources
configured for it yet. To find out where to go from here, visit the
[dropwizard documentation](dropwizard.codahale.com).

There is a working service, liquibase migrations, hibernate support and
a basic gradle build system including some
shortcuts to the commands for running migrations and starting the
service.

Enjoy!

<proj>
      +- src
          +- main
          |   +- groovy
          |   |     +- your.package.structure
          |   |           +- core
          |   |           +- db
          |   |           +- healthchecks
          |   |           +- resources
          |   |           +- core
          |   +- resources
          |
          +- test
              +- groovy
              |     +- // Spock tests in here!
              +- resources
                    +- fixtures

# Running The Application

To test the example application run the following commands.

* To run the tests run

`gradle test`

* To package the example run.

        gradle shadow

* To drop an existing h2 database run.

        gradle dropAll

* To setup the h2 database run.

        gradle migrate

* To run the server run.

        gradle run

Project created in /Users/kboon/temp!

And you’re ready to go! At this point you can run the service using gradle run. Gradle will build and test the application, create a runnable jar with the shadow plugin and then start the service. When you do, you will notice a warning from dropwizard because there are no resources defined yet so there are no available routes for the service. This is where you pick up…

The next version of the template will include gradle tasks to generate swager documention and run gatling load tests.

Comments