Mapstruct fluent extensions generator
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
-
Apply the
KAPT
plugin.plugins { id("org.jetbrains.kotlin.kapt") version "1.3.72" }
-
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
- Create an issue and describe your problem/suggestion in it.
- Submit a pull request with a reference to the issue that the pull request closes.
- I will review your changes and merge them.
- 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
- Mikhail @driver733 Yakushin - Initial work
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.