vscode-java
vscode-java copied to clipboard
annotation processor of mapstruct can not generate Impl class in vscode.
Mapstruct has supported IDEA and eclipse to generate copier class automatically,but VSCODE doesn't work. https://mapstruct.org/documentation/ide-support/
Steps To Reproduce
1.define java class @Mapper(componentModel = "spring") public interface AccountingFlowDtoCopier extends ObjectCopier<AccountingFlow, AccountingFlowDto> { }
2.gradle build
works and generate AccountingFlowDtoCopierImpl.class to {projectRootDir}/build dir.
2.VSCODE compile file to {projectRootDir}/bin dir and AccountingFlowDtoCopierImpl.class can not generate.
is there some magic? thank!
Please attach a sample project reproducing the issue
I tested with a Maven project and it worked fine. Since you're using gradle, you might want to follow the instructions in http://dplatz.de/blog/2018/gradle-apt.html so that annotation processing configuration files can be generated by gradle
Please attach a sample project reproducing the issue
It's my demo project. bin/ dir is generated by VSCODE and build/ dir is generated by "gradle build". bin/ dir does't generate DemoCopierImpl.class but build dir does. https://github.com/yousetme/mapstruct-gradle-demo
I tested with a Maven project and it worked fine. Since you're using gradle, you might want to follow the instructions in http://dplatz.de/blog/2018/gradle-apt.html so that annotation processing configuration files can be generated by gradle
I have try in VSCODE,but it does't work, perhaps it works with Eclipse.
your example doesn't even build from CLI:
./gradlew build ✔ 11:12:33
Welcome to Gradle 5.6.2!
Here are the highlights of this release:
- Incremental Groovy compilation
- Groovy compile avoidance
- Test fixtures for Java projects
- Manage plugin versions via settings script
For more details see https://docs.gradle.org/5.6.2/release-notes.html
Starting a Gradle Daemon, 6 busy and 1 incompatible Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/fbricon/Dev/souk/mapstruct-gradle-demo/build.gradle' line: 2
* What went wrong:
A problem occurred evaluating root project 'halo'.
> Could not get resource 'http://saos-publish-test.chj.cloud/gradle/version.gradle'.
> Could not GET 'http://saos-publish-test.chj.cloud/gradle/version.gradle'.
> saos-publish-test.chj.cloud: nodename nor servname provided, or not known
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s
your example doesn't even build from CLI:
./gradlew build ✔ 11:12:33 Welcome to Gradle 5.6.2! Here are the highlights of this release: - Incremental Groovy compilation - Groovy compile avoidance - Test fixtures for Java projects - Manage plugin versions via settings script For more details see https://docs.gradle.org/5.6.2/release-notes.html Starting a Gradle Daemon, 6 busy and 1 incompatible Daemons could not be reused, use --status for details FAILURE: Build failed with an exception. * Where: Build file '/Users/fbricon/Dev/souk/mapstruct-gradle-demo/build.gradle' line: 2 * What went wrong: A problem occurred evaluating root project 'halo'. > Could not get resource 'http://saos-publish-test.chj.cloud/gradle/version.gradle'. > Could not GET 'http://saos-publish-test.chj.cloud/gradle/version.gradle'. > saos-publish-test.chj.cloud: nodename nor servname provided, or not known * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 6s
https://github.com/yousetme/mapstruct-gradle-demo So sorry to waste your time, it's my negligence to import some no use code. I have clear it, have a try please. thanks.
this problem is resolved, gradle demo https://github.com/yousetme/mapstruct-gradle-demo
is work in VSCODE with http://dplatz.de/blog/2018/gradle-apt.html
.
our project is not work in VSCODE, i think it's gradle version or it's dependence version problem.
Thanks!
I have the same problem but I am using maven for the build. This are the dependency which I am using
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>
Here is a build plugin
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>xxx</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>${java.version}</release>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>-Amapstruct.defaultComponentModel=spring</compilerArgs>
</configuration>
</plugin>
</plugins>
No Impl class is generated. @fbricon any help or suggestion on this. Thank you
Still not available in VSCODE?
got the same problem
Getting the same problem, any updates?
works fine when building with gradle command, looks like mainly a vscode thing.
@PandaGeek1024 @pumano @chiragai could you attach a project example?
@snjeza yes, I prepare repo for it: https://github.com/pumano/vscode-mapstruct-tests
just check via gradle clean test
and then try to run via vscode.
You got java.lang.ExceptionInInitializerError
which Caused by: java.lang.ClassNotFoundException: Cannot find implementation for com.example.vscode.mapstructdemo.mappers.ExampleMapper
looks like path to generated
code by annotation processor not included to tests.
@pumano could you try the following patch:
diff --git a/build.gradle b/build.gradle
index 18beeb8..965f6de 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,6 +2,7 @@ plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
+ id 'eclipse'
}
group = 'com.example.vscode'
@@ -26,3 +27,14 @@ dependencies {
test {
useJUnitPlatform()
}
+
+eclipse {
+ classpath {
+ containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
+ file.whenMerged { cp ->
+ def entries = cp.entries;
+ def src = new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/generated/sources/annotationProcessor/java/main/', null)
+ entries.add(src)
+ }
+ }
+}
@snjeza wow! Works like a charm! Would be good to have it out of the box if possible.
Ok for this simple project problem solved, but for multimodule gradle project - same problem.
Ok for this simple project problem solved, but for multimodule gradle project - same problem.
@pumano could you attach a multimodule project?
Ok for this simple project problem solved, but for multimodule gradle project - same problem.
@pumano could you attach a multimodule project?
Ok I will prepare it soon
I have the same problem. When can you fix it?
Hello everyone! I am happy to say I found a way to solve this. I got it working with Spring Boot + Lombok + Mapstruct with Maven Wrapper. The key is to put the mapstuct and mapstruct-processor as dependencies. Here is how the result pom.xml looks like.
<properties>
<java.version>11</java.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
</properties>
<dependencies>
<!--Spring Boot dependencies omitted for brevity-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
<exclude>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</exclude>
<exclude>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
@ad798 It's good, but how to solve this via gradle...
I have the same problem but I am using maven for the build. This are the dependency which I am using
<dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>${mapstruct.version}</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </dependency>
Here is a build plugin
<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>xxx</mainClass> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>${java.version}</release> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> </annotationProcessorPaths> <compilerArgs>-Amapstruct.defaultComponentModel=spring</compilerArgs> </configuration> </plugin> </plugins>
No Impl class is generated. @fbricon any help or suggestion on this. Thank you
Was this problem solved? I just got the same one. @chiragai Thanks
@snjeza wow! Works like a charm! Would be good to have it out of the box if possible.
Ok for this simple project problem solved, but for multimodule gradle project - same problem.
yeah!
I have the same problem but I am using maven for the build. This are the dependency which I am using
<dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>${mapstruct.version}</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </dependency>
Here is a build plugin
<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>xxx</mainClass> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>${java.version}</release> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> </annotationProcessorPaths> <compilerArgs>-Amapstruct.defaultComponentModel=spring</compilerArgs> </configuration> </plugin> </plugins>
No Impl class is generated. @fbricon any help or suggestion on this. Thank you
Was this problem solved? I just got the same one. @chiragai Thanks
I solved this problem by adding this dependency in my project module, while my project compiled succeessfully but didn't generate implementation classes.
`
`<groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <scope>compile</scope>
Hello, I am getting the same error when mapstruct generates impl class for my Mapper, one of the classes is not listed as import. Then if I open the impl class I'm able import the package, but mapstruct doesn't not import it during generation of the class and therefore the class could not be used. I'm using gradle and Intelij. Is there any updates or work done on this?
I have the same problem but I am using gradle for the build. When I run project then mapper impl class couldn't generate. How can i solve the problem.
@javohircomunity I have managed to find a way to get this running by using in my interface the following annotation:
@Mapper(componentModel = "spring", imports = <YourClass>.class)
public interface SomeClassMapper {
// the SomeClassMapperImpl which is generated by mapstruct now imports YourClass
}
@javohircomunity I have managed to find a way to get this running by using in my interface the following annotation:
@Mapper(componentModel = "spring", imports = <YourClass>.class) public interface SomeClassMapper { // the SomeClassMapperImpl which is generated by mapstruct now imports YourClass }
I haven't any import class, There are many String fields.
*Impl.class didn't generate by vscode run , but it work well by gradle bootRun. So everytime I copy *Impl.class from build(gradle compile folder) to bin(vscode compile folder) by hand let vscode to run.
@ad798 It's good, but how to solve this via gradle...
@snjeza 's patch is fixing it: https://github.com/redhat-developer/vscode-java/issues/1660#issuecomment-818274055