mapstruct / mapstruct-examples

Examples for using MapStruct
Other
1.3k stars 508 forks source link

ClassNotFoundException: Cannot find implementation for com.mytest.mapstructtest.UserMapper #45

Closed nadjin closed 6 years ago

nadjin commented 6 years ago

IDE : intelij 2018.2 demo : mapstruct-on-gradle run result : Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: Cannot find implementation for org.mapstruct.example.SourceTargetMapper why?

filiphr commented 6 years ago

How is your IntelliJ configured? Are you delegating the build to gradle or not?

nadjin commented 6 years ago

@filiphr yes. the project has builded by gradle, InteliJ has installed mapstrcut support plugin. i have no idea now. help me~~

VictorChow commented 6 years ago

same problem . java.lang.ClassNotFoundException: Cannot find implementation for org.mapstruct.example.SourceTargetMapper

nadjin commented 6 years ago

@filiphr this is my config. 1 2 3

VictorChow commented 6 years ago

Add sourceSets in build.gradle, it works.

sourceSets {
    main.java.srcDirs += "build/generated/source/apt/main"
}
ft0907 commented 6 years ago

@VictorChow @nadjin How do you solve this problem? I can now generate the implementation class, but I always prompt when injecting objects. java.lang.ClassNotFoundException: Cannot find implementation

VictorChow commented 6 years ago

@ft0907 add generated folder into sourceSets

ft0907 commented 6 years ago

@VictorChow Thank you very much for your answer, but I do not have this folder path.
I have generated class and corresponding java files in the /build/classes folder. Is there a problem with the path to generate files?

VictorChow commented 6 years ago

screen shot 2018-08-28 at 5 02 06 pm screen shot 2018-08-28 at 5 00 41 pm @ft0907

nadjin commented 6 years ago

@VictorChow Thank U so much, I did but it doesn't work.. o( ̄┰ ̄*)ゞ `plugins { id 'java' id 'net.ltgt.apt' version '0.9' } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot'

dependencies { compile('org.springframework.boot:spring-boot-starter-web') compileOnly 'org.mapstruct:mapstruct-jdk8:1.2.0.Final', 'org.projectlombok:lombok:1.+' apt 'org.mapstruct:mapstruct-processor:1.2.0.Final', 'org.projectlombok:lombok:1.+' }

sourceSets { main.java.srcDirs += "build/generated/source/apt/main" } `

VictorChow commented 6 years ago

@nadjin i use gradle-4.10-all

nadjin commented 6 years ago

@VictorChow Thank u. @filiphr VictorChow show the path , you can do like this 1 2

then add sourceSets { main.java.srcDirs += "build/generated/source/apt/main" } in build.gradle
i will try other way .

ft0907 commented 6 years ago

dependencies { classpath "net.ltgt.gradle:gradle-apt-plugin:0.18" } apply plugin: "net.ltgt.apt-eclipse" compile 'org.mapstruct:mapstruct-jdk8:1.3.0.Beta1' compile 'org.mapstruct:mapstruct-processor:1.3.0.Beta1'

//If you add this line to annotate gradle build, you will make a mistake. annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Beta1'

This is my configuration in gradle. But I configure it to generate build/generated/source/apt.....XxImpl However, class executable files cannot be generated in the running directory. The STS editor I used I guess it should have something to do with my gradle-apt-plugin. Can you generate class files and run successfully? @nadjin @VictorChow

ft0907 commented 6 years ago

It has been able to run normally, but it is actually a version of Lombok.

dependencies { classpath 'io.franzbecker:gradle-lombok:1.11' classpath "net.ltgt.gradle:gradle-apt-plugin:0.18" } apply plugin: "net.ltgt.apt-eclipse" apply plugin: 'io.franzbecker.gradle-lombok'

lombok { version = '1.18.0' }

dependencies { compileOnly 'org.projectlombok:lombok' compile 'org.mapstruct:mapstruct-jdk8:1.3.0.Beta1' annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Beta1' annotationProcessor 'org.projectlombok:lombok' }

sourceSets { main.java.srcDirs += "build/generated/source/apt/main" }

It's similar to the @filiphr example, but requires additional configuration of sourceSets. Is there anywhere you can configure this path by default!!!

filiphr commented 6 years ago

In order for IntelliJ to be properly configured one needs to use the following plugin:

apply plugin: "net.ltgt.apt-idea"

You are all using the gradle-apt-plugin. I think that once you have this IntelliJ should be able to configure itself correctly.

BVijayKrishna commented 5 years ago

Add sourceSets in build.gradle, it works.

sourceSets {
    main.java.srcDirs += "build/generated/source/apt/main"
}

@VictorChow I added this but still, getting the same error. I'm using gradle 3.4 version

eapereira commented 4 years ago

my project uses this path, I using the now configuration for 1.3.1.Final guide:


sourceSets {
    main.java.srcDirs += "build/generated/sources/annotationProcessor/java/main"
}

Now it works fine! Thanks!

bawantha commented 1 year ago

any ideas for maven ?

csankhala commented 1 year ago

Following things worked for me in addition to sourceSet changes:

@Mapper(componentModel = "jsr330")

Add componentModel for Mapper class