|
6 | 6 |
|
7 | 7 | Hermes is a Maven plugin designed to streamline the generation of fluent object builders for your Java classes. Employing a declarative approach, it produces a straightforward Domain Specific Language (DSL) to facilitate the construction of object instances. |
8 | 8 |
|
9 | | - |
10 | | -## Annotations |
11 | | - |
12 | | -- **@DSLRoot** - Indicates the intention to create a builder for the annotated class; |
13 | | -- **@DSLProperty** - Customizes the method name generated for a specific field. The default is the original field name; |
14 | | -- **@DSLIgnore** - Marks a field to be excluded when generating DSL code; |
| 9 | +## Update your pom.xml file |
| 10 | + |
| 11 | +```xml |
| 12 | +<repositories> |
| 13 | + <repository> |
| 14 | + <id>jitpack.io</id> |
| 15 | + <url>https://jitpack.io</url> |
| 16 | + </repository> |
| 17 | +</repositories> |
| 18 | + |
| 19 | +<dependencies> |
| 20 | + <dependency> |
| 21 | + <groupId>com.github.victorhsr</groupId> |
| 22 | + <artifactId>hermes-maven-plugin</artifactId> |
| 23 | + <version>Tag</version> |
| 24 | + </dependency> |
| 25 | +</dependencies> |
| 26 | +``` |
15 | 27 |
|
16 | 28 | ## Usage |
17 | 29 | Suppose we have classes `Person`, `Address` and `MetaDataWrapper` annotated with `@DSLRoot` and `@DSLProperty`: |
@@ -67,6 +79,12 @@ Person personFromDsl = |
67 | 79 |
|
68 | 80 | Note that there's no need to instantiate `Address` or `MetaDataWrapper`, and more descriptive names for Person's fields can be used. |
69 | 81 |
|
| 82 | +## Annotations |
| 83 | + |
| 84 | +- **@DSLRoot** - Indicates the intention to create a builder for the annotated class; |
| 85 | +- **@DSLProperty** - Customizes the method name generated for a specific field. The default is the original field name; |
| 86 | +- **@DSLIgnore** - Marks a field to be excluded when generating DSL code; |
| 87 | + |
70 | 88 | # Comparison with Traditional Java Classes |
71 | 89 |
|
72 | 90 | The equivalent implementation in traditional Java code involves a considerable amount of boilerplate: |
@@ -102,7 +120,7 @@ private Address buildAddress() { |
102 | 120 | ``` |
103 | 121 | That's a lot of code, almost twice the lines of our previous implementation. The Hermes Maven Plugin significantly reduces this boilerplate, providing a more concise and readable alternative. |
104 | 122 |
|
105 | | -# Using Lombok for Comparison |
| 123 | +# Using Lombok for comparison |
106 | 124 |
|
107 | 125 | An alternative approach using Lombok involves a cleaner syntax but may lack readability and customization |
108 | 126 |
|
|
0 commit comments