Mapstruct and Lombok

2,966 views
Skip to first unread message

COTTET Julien

unread,
Sep 29, 2014, 4:42:36 AM9/29/14
to mapstru...@googlegroups.com
Hello,
We're using lombok (http://projectlombok.org/) on our project, and want to use Mapstruct.

If we want to do that, we need to refactor all our code to put getter and setter back.

Do you have a solution to work with the two library (mapstruct and lombok) ?

Have you planified a release to make these anotations (@Setter, @Getter, @Data) fonctionnal with mapstruct ?

Thanks in advance.

Sjaak Derksen

unread,
Sep 29, 2014, 5:56:48 AM9/29/14
to mapstru...@googlegroups.com
Hey Julien,

Did you separate the Lombok project and the MapStruct into 2 projects? If you do so, the MapStruct project could use the Lombok project to do its mapping.

AFAIK Lombok generates (in a kind of dirty way) getters and setters (and toString, etc) based on source files that only have properties. It uses a trick in the annotation processor, so you don't see the result in the source. However the generated jar does have the getters and setters you need. 

Best regards,
Sjaak

Gunnar Morling

unread,
Sep 29, 2014, 10:55:12 AM9/29/14
to mapstru...@googlegroups.com

Hi Julien,

We don't have planned anything in that direction yet, but it sounds like an interesting idea.

I don't know Lombok really well, do you have any idea in which way it should be supported specifically? Would you be interested in contributing this feature to MapStruct?

As Sjaak is saying, you may work with two separate projects for the time being.

--Gunnar

Sjaak Derksen

unread,
Oct 8, 2014, 3:48:55 PM10/8/14
to mapstru...@googlegroups.com

Hi Julien,

I attached a very simple example


Best regards,
Sjaak

On Monday, September 29, 2014 10:42:36 AM UTC+2, COTTET Julien wrote:
MapStructEx3.zip

Marvin Froeder

unread,
Oct 8, 2014, 3:58:15 PM10/8/14
to Sjaak Derksen, mapstru...@googlegroups.com
FWIW,  We are using both here w/o any issue.

I built you project and it worked.

Do I need to do anything else besides mvn clean install?

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sjaak Derksen

unread,
Oct 8, 2014, 4:11:08 PM10/8/14
to mapstru...@googlegroups.com
Clean install should generate the mapper implementation. You could then run the Tst.class in the mapper project.

Marvin Froeder

unread,
Oct 8, 2014, 5:03:29 PM10/8/14
to Sjaak Derksen, mapstru...@googlegroups.com
Ow, you need to add generated sources to your IDE

It goes like
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

--

COTTET Julien

unread,
Oct 9, 2014, 6:03:23 AM10/9/14
to mapstru...@googlegroups.com
Hi Sjaak,

Thanx for that project you've joined.

It works like a charm and is exactly what i wanted to do.

All the team i'm in, will be happy of that news.

Gunnar Morling

unread,
Oct 9, 2014, 6:01:11 PM10/9/14
to COTTET Julien, mapstru...@googlegroups.com
2014-10-09 12:03 GMT+02:00 COTTET Julien <tet...@gmail.com>:
Hi Sjaak,

Thanx for that project you've joined.

It works like a charm and is exactly what i wanted to do.

All the team i'm in, will be happy of that news.

Cool!

Thanks to Sjaak, the Lombok example also is part of the "mapstruct-examples" project now: https://github.com/mapstruct/mapstruct-examples

--Gunnar
 

Le mercredi 8 octobre 2014 21:48:55 UTC+2, Sjaak Derksen a écrit :

Hi Julien,

I attached a very simple example

Best regards,
Sjaak

On Monday, September 29, 2014 10:42:36 AM UTC+2, COTTET Julien wrote:
Hello,
We're using lombok (http://projectlombok.org/) on our project, and want to use Mapstruct.

If we want to do that, we need to refactor all our code to put getter and setter back.

Do you have a solution to work with the two library (mapstruct and lombok) ?

Have you planified a release to make these anotations (@Setter, @Getter, @Data) fonctionnal with mapstruct ?

Thanks in advance.

--
Reply all
Reply to author
Forward
0 new messages