Gradle plugin for easy MapStruct setup
- Gradle: 9.0 or higher
- Java: 17 or higher
plugins {
id 'io.github.akazver.mapstruct' version 'X.Y.Z'
}The plugin automatically:
- Adds MapStruct dependencies (
mapstructandmapstruct-processor) - Detects optional dependencies (Lombok, Spring, Camel, Quarkus, Protobuf) in your project
- Adds required binding libraries when needed (e.g.,
lombok-mapstruct-bindingfor Lombok) - Detects Kotlin and automatically applies
kaptplugin with proper configuration - Configures compiler arguments based on your
mapstruct {}block settings - Runs after project evaluation to ensure all dependencies are resolved
| Category | GitHub | Maven | Configuration |
|---|---|---|---|
| MapStruct (required) | mapstruct/mapstruct | org.mapstruct/mapstruct | implementation |
| org.mapstruct/mapstruct-processor | annotationProcessor |
||
| Lombok | projectlombok/lombok | org.projectlombok/lombok-mapstruct-binding | annotationProcessor |
| Spring | mapstruct/mapstruct-spring-extensions | org.mapstruct.extensions.spring/mapstruct-spring-annotations | implementation |
| org.mapstruct.extensions.spring/mapstruct-spring-extensions | annotationProcessor |
||
| org.mapstruct.extensions.spring/mapstruct-spring-test-extensions | testImplementation |
||
| Camel | apache/camel | org.apache.camel/camel-mapstruct | implementation |
| apache/camel-spring-boot | org.apache.camel.springboot/camel-mapstruct-starter | implementation |
|
| apache/camel-quarkus | org.apache.camel.quarkus/camel-quarkus-mapstruct | implementation |
|
| Quarkus | quarkiverse/quarkus-mapstruct | io.quarkiverse.mapstruct/quarkus-mapstruct | implementation |
| Protobuf | entur/mapstruct-spi-protobuf | no.entur.mapstruct.spi/protobuf-spi-impl | annotationProcessor |
Plugin adds configuration block which looks like this:
mapstruct {
suppressGeneratorTimestamp = true
verbose = true
suppressGeneratorVersionInfoComment = true
defaultComponentModel = 'spring'
defaultInjectionStrategy = 'constructor'
unmappedTargetPolicy = 'ERROR'
unmappedSourcePolicy = 'ERROR'
disableBuilders = true
nullValueIterableMappingStrategy = 'RETURN_DEFAULT'
nullValueMapMappingStrategy = 'RETURN_DEFAULT'
}All parameters used according to official documentation
Make sure you have the Java plugin applied and that annotation processing is enabled in your IDE.
The plugin automatically adds lombok-mapstruct-binding when Lombok is detected. If you still have issues, ensure
Lombok plugin is applied before MapStruct plugin.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request