Mapstruct-fluent

Generator of fluent extension functions for mapstruct mappers

License

License

Categories

Categories

MapStruct General Purpose Libraries Bean Mapping
GroupId

GroupId

com.driver733.mapstruct-fluent
ArtifactId

ArtifactId

processor-spring
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

module
Description

Description

Mapstruct-fluent
Generator of fluent extension functions for mapstruct mappers
Project URL

Project URL

https://github.com/driver733/mapstruct-fluent
Source Code Management

Source Code Management

https://github.com/driver733/mapstruct-fluent

Download processor-spring

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.30

runtime (10)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-reflect jar 1.4.30
org.jetbrains.kotlinx : kotlinx-coroutines-core-jvm jar 1.4.2
org.jetbrains.kotlinx : kotlinx-coroutines-test jar 1.4.2
com.fasterxml.jackson.module : jackson-module-kotlin jar 2.11.1
org.awaitility : awaitility-kotlin jar 4.0.3
org.mapstruct : mapstruct jar 1.4.2.Final
com.google.auto.service : auto-service jar 1.0-rc6
com.squareup : kotlinpoet jar 1.5.0
com.driver733.mapstruct-fluent : common jar 1.1.1
org.springframework.boot : spring-boot-starter jar 2.3.0.RELEASE

Project Modules

There are no modules declared in this project.

Mapstruct fluent extensions generator

Build Maven Central

semantic-release

Licence

This project provides a generator of fluent extension functions for mapstruct mappers.

Examples

Extension method for the mappers' factory

data class EmployeeModel(val firstName: String? = null)
data class EmployeeView(val firstName: String? = null)
@Mapper
abstract class EmployeeMapper {
    abstract fun toEmployeeView(employeeModel: EmployeeModel): EmployeeView
}
val employee = EmployeeView("Alex")
employee.toEmployeeView() == Mappers.getMapper(EmployeeMapper::class.java).toEmployeeView(employee)

Extension method for the mapper's Spring bean

data class EmployeeModel(val firstName: String? = null)
data class EmployeeView(val firstName: String? = null)
@Mapper(componentmodel = "spring")
abstract class EmployeeMapper {
    abstract fun toEmployeeView(employeeModel: EmployeeModel): EmployeeView
}

Calling the generated extension function

@Service
class Service {
    fun a() {
        val model = EmployeeModel("Alex")
        val view = employee.toEmployeeView()
    }
}

is the same as manually using the mapper's Spring bean

@Service
class Service(
    private val mapper: EmployeeMapper
) {
    fun a() {
        val model = EmployeeModel("Alex")
        val view = mapper.toEmployeeView(employee)
    }
}

Distribution

This project is available on the Maven Central repository.

Getting Started

Install

Gradle

Groovy DSL

Add this to your project's build.gradle:

dependencies {
    annotationProcessor 'com.driver733.mapstruct-fluent:processor:1.0.3'
    implementation 'com.driver733.mapstruct-fluent:processor:1.0.3'
    annotationProcessor 'com.driver733.mapstruct-fluent:processor-spring:1.0.3'
    implementation 'com.driver733.mapstruct-fluent:processor-spring:1.0.3'
}
Kotlin DSL
  1. Apply the KAPT plugin.

    plugins {
      id("org.jetbrains.kotlin.kapt") version "1.3.72"
    }
  2. Add this to your project's build.gradle.kts:

    dependencies {
        kapt("com.driver733.mapstruct-fluent:processor:1.0.3")
        implementation("com.driver733.mapstruct-fluent:processor:1.0.3")
        kapt("com.driver733.mapstruct-fluent:processor-spring:1.0.3")
        implementation("com.driver733.mapstruct-fluent:processor-spring:1.0.3")
    }

Maven

Add this to your project's pom.xml:

<dependencies>
    <dependency>
      <groupId>com.driver733.mapstruct-fluent</groupId>
      <artifactId>processor</artifactId>
      <version>1.0.3</version>
    </dependency>
    <dependency>
      <groupId>com.driver733.mapstruct-fluent</groupId>
      <artifactId>processor-spring</artifactId>
      <version>1.0.3</version>
    </dependency>
</dependencies>
<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>...</version>
            <configuration>
                <annotationProcessorPaths>
                    <annotationProcessorPath>
                        <groupId>com.driver733.mapstruct-fluent</groupId>
                        <artifactId>processor</artifactId>
                        <version>1.0.3</version>
                    </annotationProcessorPath>
                   <annotationProcessorPath>
                        <groupId>com.driver733.mapstruct-fluent</groupId>
                        <artifactId>processor-spring</artifactId>
                        <version>1.0.3</version>
                    </annotationProcessorPath>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

Development

Prerequisites

JDK, preferably >= v. 1.8

Build

./gradlew clean build

CI/CD

Github actions is used for CI/CD.

Releases

Releases to the Maven Central repository are automatically made on each commit on the master branch with the help of the semantic-release.

Contributing

  1. Create an issue and describe your problem/suggestion in it.
  2. Submit a pull request with a reference to the issue that the pull request closes.
  3. I will review your changes and merge them.
  4. A new version with your changes will be released automatically right after merging.

Versioning

We use SemVer for versioning. For the versions available, see the tags.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

Versions

Version
1.1.1
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0