{"id":3397,"date":"2023-02-21T22:55:35","date_gmt":"2023-02-22T01:55:35","guid":{"rendered":"https:\/\/danillolima.com\/en\/?p=3397"},"modified":"2023-02-21T22:56:30","modified_gmt":"2023-02-22T01:56:30","slug":"the-cannot-find-symbol-error-when-using-mapstruct-with-lombok","status":"publish","type":"post","link":"https:\/\/danillolima.com\/en\/java\/the-cannot-find-symbol-error-when-using-mapstruct-with-lombok\/","title":{"rendered":"The &#8220;Cannot find symbol&#8221; error when using MapStruct with Lombok"},"content":{"rendered":"\n<p>If you are having the problem &#8220;Cannot find symbol&#8221; with your Java project compilation because the compiler doesn&#8217;t recognize the methods calls of getters, setters, constructors, etc., but your IDE is still recognizing the methods normally, you probably forgot to configure your <code>pom.xml<\/code> or <code>build.gradle<\/code> for multiple annotation processors with the MapStruct library. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"756\" src=\"https:\/\/danillolima.com\/en\/wp-content\/uploads\/sites\/2\/2023\/02\/image-1024x756.png\" alt=\"\" class=\"wp-image-3406\" title=\"\" srcset=\"https:\/\/danillolima.com\/en\/wp-content\/uploads\/sites\/2\/2023\/02\/image-1024x756.png 1024w, https:\/\/danillolima.com\/en\/wp-content\/uploads\/sites\/2\/2023\/02\/image-300x221.png 300w, https:\/\/danillolima.com\/en\/wp-content\/uploads\/sites\/2\/2023\/02\/image-768x567.png 768w, https:\/\/danillolima.com\/en\/wp-content\/uploads\/sites\/2\/2023\/02\/image.png 1207w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">WARNING: If you&#8217;re using Intellij IDE check if the option &#8220;Enable annotation processing&#8221; is checked.<\/figcaption><\/figure>\n\n\n\n<p>If your problem is more general, you can try the solutions provided in the <a href=\"https:\/\/www.baeldung.com\/java-cannot-find-symbol-error\" target=\"_blank\" rel=\"noreferrer noopener\">Baeldung post<\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>In my case, the problem of &#8220;Cannot find symbol&#8221; was that I forgot to pass all the paths of the annotation processors that I was using to the Maven compiler. In the <a href=\"https:\/\/github.com\/mapstruct\/mapstruct-examples\/tree\/main\/mapstruct-lombok\" target=\"_blank\" rel=\"noreferrer noopener\">examples of MapStruct project<\/a>, you can check the correct configurations to make it work together with Lombok correctly.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">...\n&lt;plugin>\n    &lt;groupId>org.apache.maven.plugins&lt;\/groupId>\n    &lt;artifactId>maven-compiler-plugin&lt;\/artifactId>\n    &lt;version>3.8.1&lt;\/version>\n    &lt;configuration>\n        &lt;source>${java.version}&lt;\/source>\n        &lt;target>${java.version}&lt;\/target>\n        &lt;annotationProcessorPaths>\n            &lt;path>\n                &lt;groupId>org.mapstruct&lt;\/groupId>\n                &lt;artifactId>mapstruct-processor&lt;\/artifactId>\n                &lt;version>${org.mapstruct.version}&lt;\/version>\n            &lt;\/path>\n            &lt;path>\n                &lt;groupId>org.mapstruct&lt;\/groupId>\n                &lt;artifactId>mapstruct-processor&lt;\/artifactId>\n                &lt;version>${org.mapstruct.version}&lt;\/version>\n            &lt;\/path>\n            &lt;path>\n                &lt;groupId>org.projectlombok&lt;\/groupId>\n                &lt;artifactId>lombok&lt;\/artifactId>\n                &lt;version>${lombok.version}&lt;\/version>\n            &lt;\/path>\n            &lt;path>\n                &lt;groupId>org.projectlombok&lt;\/groupId>\n                &lt;artifactId>lombok-mapstruct-binding&lt;\/artifactId>\n                &lt;version>${lombok-mapstruct-binding}&lt;\/version>\n            &lt;\/path>\n        &lt;\/annotationProcessorPaths>\n    &lt;\/configuration>\n&lt;\/plugin>\n...<\/pre>\n\n\n\n<p>Good to remember: <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>If you are using Lombok 1.18.16 or newer you also need to add&nbsp;<a href=\"https:\/\/search.maven.org\/artifact\/org.projectlombok\/lombok-mapstruct-binding\" target=\"_blank\" rel=\"noopener\">lombok-mapstruct-binding<\/a>&nbsp;in order to make Lombok and MapStruct work together.<\/p>\n<cite><a href=\"https:\/\/mapstruct.org\/faq\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/mapstruct.org\/faq\/<\/a><\/cite><\/blockquote>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/mapstruct\/mapstruct-examples\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/mapstruct\/mapstruct-examples\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/mapstruct.org\/documentation\/installation\/\" target=\"_blank\" rel=\"noopener\">https:\/\/mapstruct.org\/documentation\/installation\/<\/a> <\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>If you are having the problem &#8220;Cannot find symbol&#8221; with your Java project compilation because the compiler doesn&#8217;t recognize the methods calls of getters, setters, constructors, etc., but your IDE is still recognizing the methods normally, you probably forgot to configure your pom.xml or build.gradle for multiple annotation processors with the MapStruct library. If your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3415,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-3397","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts\/3397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/comments?post=3397"}],"version-history":[{"count":17,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts\/3397\/revisions"}],"predecessor-version":[{"id":3416,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts\/3397\/revisions\/3416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/media\/3415"}],"wp:attachment":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/media?parent=3397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/categories?post=3397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/tags?post=3397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}