0

as you've read in the title, I have a problem using Mapstruct with Kotlin and Maven.

(FYI: The solutions in this post didn't resolve the issue for me).

Following mapstruct-examples/mapstruct-kotlin, I've added the kapt plugin alongside the dependency to my project-roots <pluginManagement>:

<!-- Cut out non-kapt executions -->
<execution>
    <id>kapt</id>
    <goals>
        <goal>kapt</goal>
    </goals>

    <configuration>
        <sourceDirs>
            <sourceDir>src/main/kotlin</sourceDir>
            <sourceDir>src/main/java</sourceDir>
        </sourceDirs>
        <annotationProcessorPaths>
            <annotationProcessorPath>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${org.mapstruct.version}</version> <!-- :1.5.5.Final -->
            </annotationProcessorPath>
        </annotationProcessorPaths>
    </configuration>
</execution>

Then I use it in each sub module like so:

<!-- Cut out unnecessary stuff again -->
<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
</plugin>

Just in case it helps clearing some questions, here's the Mapper:

@Mapper
interface CustomMapper {

    fun toDTO(entity: Entity): DTO

    fun toEntity(dto: DTO): Entity
}

1 Answer 1

1

The solution to my problem was rather easy to pull off and had an even dumber source to begin with.

The app I used Mapstruct in was a multi module project. Two of these modules depended on each other => Thus there was a cyclic dependency.

I refactored the modules to not be dependent on one and each other and that seemed to solve the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.