no

How to fix cannot find symbol error with maven, mapstruct, lombok builder and javadoc

When developing a Spring REST service we often used a DTO for different microservices communication. Once this message is received in one of...

When developing a Spring REST service we often used a DTO for different microservices communication. Once this message is received in one of the services it is then passed to the lower service level. 

1. Problem

A DTO contains constructors, builders, getters, and setters. It's not a problem when you only have one or two but maintaining a dozen is different.

The service layer has its own object or POJO that it accepts. Thus we need a way to copy the content of the DTO to the POJO. And POJO further down to the entity level. It's really a pain when you have a dozen.

2. Solution

We use Lombok to help us with the automatic generation of constructors, builders, getters, and setters. And it does more than that.

For copying the content of one object to another, we use Mapstruct.

3. Cannot Find Symbol Problem

To solve this problem and to enable a smooth Maven, Mapstruct, Lombok, and JavaDoc integration we have to define these plugins as such.
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${maven.compiler.plugin.version}</version>
  <configuration>
	<source>${java.version}</source>
	<target>${java.version}</target>
	<compilerArgument>-Xlint:unchecked</compilerArgument>
	<showDeprecation>true</showDeprecation>
	<showWarnings>true</showWarnings>
	<annotationProcessorPaths>
	  <path>
		<groupId>org.projectlombok</groupId>
		<artifactId>lombok</artifactId>
		<version>${lombok.version}</version>
	  </path>
	  <path>
		<groupId>org.mapstruct</groupId>
		<artifactId>mapstruct-processor</artifactId>
		<version>${mapstruct.version}</version>
	  </path>
	  <path>
		<groupId>org.projectlombok</groupId>
		<artifactId>lombok-mapstruct-binding</artifactId>
		<version>0.2.0</version>
	  </path>
	</annotationProcessorPaths>
  </configuration>
</plugin>
<plugin>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok-maven-plugin</artifactId>
  <version>${lombok-maven-plugin.version}</version>
  <configuration>
	<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
	<outputDirectory>${delombok.output}</outputDirectory>
	<addOutputDirectory>false</addOutputDirectory>
  </configuration>
  <executions>
	<execution>
	  <phase>generate-sources</phase>
	  <goals>
		<goal>delombok</goal>
	  </goals>
	</execution>
  </executions>
</plugin>
<plugin>
  <artifactId>maven-javadoc-plugin</artifactId>
  <extensions>true</extensions>
  <executions>
	<execution>
	  <phase>compile</phase>
	  <goals>
		<goal>javadoc-no-fork</goal>
	  </goals>
	</execution>
	<execution>
	  <id>attach-javadocs</id>
	  <goals>
		<goal>jar</goal>
	  </goals>
	</execution>
  </executions>
  <configuration>
	<finalName>czetsuyatech-docs</finalName>
	<doclet>capital.scalable.restdocs.jsondoclet.ExtractDocumentationAsJsonDoclet</doclet>
	<docletArtifact>
	  <groupId>capital.scalable</groupId>
	  <artifactId>spring-auto-restdocs-json-doclet-jdk9</artifactId>
	  <version>${spring-auto-restdocs.version}</version>
	</docletArtifact>
	<reportOutputDirectory>${project.build.directory}</reportOutputDirectory>
	<useStandardDocletOptions>false</useStandardDocletOptions>
	<show>package</show>
	<sourcepath>${delombok.output}</sourcepath>
  </configuration>
</plugin>

Related

maven 2832993689797935255

Post a Comment Default Comments

item