Skip to content

Latest commit

 

History

History
107 lines (82 loc) · 8.8 KB

File metadata and controls

107 lines (82 loc) · 8.8 KB

Actions Status Plugin Version Quality Gate Status Coverage
Security Rating Reliability Rating Maintainability Rating Vulnerabilities
Java Gradle License FOSSA Status

MapStruct Gradle Plugin

Gradle plugin for easy MapStruct setup

Requirements

  • Gradle: 9.0 or higher
  • Java: 17 or higher

Usage

plugins {
    id 'io.github.akazver.mapstruct' version 'X.Y.Z'
}

How it works

The plugin automatically:

  • Adds MapStruct dependencies (mapstruct and mapstruct-processor)
  • Detects optional dependencies (Lombok, Spring, Camel, Quarkus, Protobuf) in your project
  • Adds required binding libraries when needed (e.g., lombok-mapstruct-binding for Lombok)
  • Detects Kotlin and automatically applies kapt plugin with proper configuration
  • Configures compiler arguments based on your mapstruct {} block settings
  • Runs after project evaluation to ensure all dependencies are resolved

Dependencies

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

Config

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

Troubleshooting

MapStruct not generating mappers

Make sure you have the Java plugin applied and that annotation processing is enabled in your IDE.

Lombok + MapStruct conflicts

The plugin automatically adds lombok-mapstruct-binding when Lombok is detected. If you still have issues, ensure Lombok plugin is applied before MapStruct plugin.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

FOSSA Status