Welcome to the Lombok Features Exploration repository! This project showcases the powerful features of the Lombok library, which is widely used to reduce boilerplate code in Java applications.
- Overview
- Features
- Getting Started
- Project Structure
- Usage Examples
- Testing
- Documentation
- Contributing
- License
Lombok simplifies Java development by automating repetitive tasks such as generating getters, setters, constructors, and more. It improves code readability and reduces boilerplate, allowing developers to focus on core logic.
This repository explores and demonstrates:
- Core annotations (e.g.,
@Getter
,@Setter
,@Data
,@Builder
) - Advanced features (e.g.,
@SneakyThrows
,@UtilityClass
, logging annotations) - Experimental capabilities
- Getters and Setters: Use
@Getter
and@Setter
to automatically generate getter and setter methods. - Constructors: Simplify constructors with
@NoArgsConstructor
,@AllArgsConstructor
, and@RequiredArgsConstructor
. - Builder Pattern: Generate builder classes with
@Builder
. - ToString, Equals, and HashCode: Generate methods using
@ToString
and@EqualsAndHashCode
. - Data Classes: Combine annotations using
@Data
. - Immutable Objects: Use
@Value
to create immutable classes.
- Exception Handling: Suppress checked exceptions with
@SneakyThrows
. - Logging: Leverage logging annotations like
@Slf4j
and@Log
. - Utility Classes: Create static utility classes with
@UtilityClass
.
- Learn about experimental annotations such as
@SuperBuilder
and others.
- Java 8+
- Maven or Gradle
-
Clone the repository:
git clone https://github.com/rvguradiya/lombok-features-exploration.git cd lombok-features-exploration
-
Add Lombok to your
pom.xml
(for Maven):<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.28</version> <scope>provided</scope> </dependency>
Or to
build.gradle
(for Gradle):implementation 'org.projectlombok:lombok:1.18.28' annotationProcessor 'org.projectlombok:lombok:1.18.28'
-
Enable annotation processing in your IDE (e.g., IntelliJ IDEA or Eclipse).
lombok-features-exploration/
├── README.md
├── pom.xml (or build.gradle)
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/
│ │ │ └── lombokfeatures/
│ │ │ ├── annotations/
│ │ │ │ ├── GetterSetterExample.java
│ │ │ │ ├── ToStringEqualsHashCodeExample.java
│ │ │ │ ├── ConstructorExample.java
│ │ │ │ ├── BuilderExample.java
│ │ │ │ ├── DataAnnotationExample.java
│ │ │ │ ├── ValueAnnotationExample.java
│ │ │ │ ├── SneakyThrowsExample.java
│ │ │ │ ├── LogExample.java
│ │ │ │ ├── ExperimentalFeaturesExample.java
│ │ │ ├── config/
│ │ │ │ ├── LombokConfigExplanation.md
│ │ │ └── utils/
│ │ │ ├── UtilityExample.java
│ ├── test/
│ ├── java/
│ └── com/
│ └── example/
│ └── lombokfeatures/
│ ├── annotations/
│ │ ├── DataAnnotationTest.java
│ │ ├── BuilderAnnotationTest.java
│ └── utils/
│ ├── UtilityExampleTest.java
├── docs/
│ ├── LombokOverview.md
│ ├── CommonPitfalls.md
│ └── FAQ.md
└── .gitignore
Explore the examples in the src/main/java/com/example/lombokfeatures/annotations
folder:
- Getter and Setter:
GetterSetterExample.java
- Constructors:
ConstructorExample.java
- Builder Pattern:
BuilderExample.java
- Data Class:
DataAnnotationExample.java
- Exception Handling:
SneakyThrowsExample.java
- Logging:
LogExample.java
Run these examples to observe the generated code and behavior.
Unit tests are included in the src/test/java/com/example/lombokfeatures
folder to validate the generated code and demonstrate best practices.
Run tests using:
mvn test
Or for Gradle:
gradle test
Additional documentation is available in the docs/
folder:
- LombokOverview.md: High-level overview of Lombok features.
- CommonPitfalls.md: Common issues and their solutions.
- FAQ.md: Frequently asked questions.
Contributions are welcome! Feel free to fork this repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.
Happy coding with Lombok! 🚀