maven-lombok-plugin, delombok: Why it is required to put the source code in src/main/lombok?

2,142 views
Skip to first unread message

tafit3

unread,
Dec 5, 2011, 4:30:43 PM12/5/11
to Project Lombok
If I want to delombok the source code I need to move it from src/main/
java to src/main/lombok. It is stated on the bottom of the page
http://awhitford.github.com/lombok.maven/maven-lombok-plugin/

"Place the java source code with lombok annotations in src/main/lombok
(instead of src/main/java)."

Why src/main/lombok and not src/main/java? Is there a way to configure
maven-lombok-plugin to process src/main/java instead of src/main/
lombok?

Nick Stolwijk

unread,
Dec 6, 2011, 8:10:50 AM12/6/11
to project...@googlegroups.com
You can adjust this directory by overriding the sourceDirectory
parameter[1]. The rationale behind this split up is unknown to me.

Hth,

Nick Stolwijk

[1] http://awhitford.github.com/lombok.maven/maven-lombok-plugin/delombok-mojo.html#sourceDirectory

> --
> You received this message because you are subscribed to the Google
> Groups group for http://projectlombok.org/
>
> To post to this group, send email to project...@googlegroups.com
> To unsubscribe from this group, send email to
> project-lombo...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/project-lombok?hl=en

tafit3

unread,
Dec 7, 2011, 12:50:13 PM12/7/11
to Project Lombok
I changed the sourceDirectory parameter, so my lombok-maven-plugin
configuration is as follows:

<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>0.10.4.0</version>
<executions>
<execution>
<id>delombok</id>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
<configuration>
<verbose>true</verbose>
<sourceDirectory>${project.basedir}/src/main/java</
sourceDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>

When I invoke maven, I get a lot of "duplicate class" errors. It is
because maven is trying to build from src/main/java and target/
generated-sources/delombok at the same time. Do you know if there is a
way to change the source directory, so that the compile:compile goal
will only use the generated sources directory?
I've tried using build-helper-maven-plugin. There is the option for
adding sources (which happens automatically in lombok-maven-plugin I
suppose), but there is no option for removing sources.

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-
sources/delombok</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Best regards,
Dawid Chodura

On 6 Gru, 14:10, Nick Stolwijk <nick.stolw...@gmail.com> wrote:
> You can adjust this directory by overriding the sourceDirectory
> parameter[1]. The rationale behind this split up is unknown to me.
>
> Hth,
>
> Nick Stolwijk
>

> [1]http://awhitford.github.com/lombok.maven/maven-lombok-plugin/delombok...


>
>
>
>
>
>
>
> On Mon, Dec 5, 2011 at 10:30 PM, tafit3 <dawid.chod...@gmail.com> wrote:
> > If I want to delombok the source code I need to move it from src/main/
> > java to src/main/lombok. It is stated on the bottom of the page
> >http://awhitford.github.com/lombok.maven/maven-lombok-plugin/
>
> > "Place the java source code with lombok annotations in src/main/lombok
> > (instead of src/main/java)."
>
> > Why src/main/lombok and not src/main/java? Is there a way to configure
> > maven-lombok-plugin to process src/main/java instead of src/main/
> > lombok?
>
> > --
> > You received this message because you are subscribed to the Google

> > Groups group forhttp://projectlombok.org/

Chris Alexander

unread,
Dec 9, 2011, 4:00:10 AM12/9/11
to project...@googlegroups.com
We had virtually the same issue in our build. We have a solution, but it is inelegant, and if I get some time I really want to try and improve it.

However, at least it does work. First we do a delombok:

<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>0.10.2.1-SNAPSHOT</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
<configuration>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<outputDirectory>${project.basedir}/src.delomboked</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
 <dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
 </dependency>
</dependencies>  
</plugin>

  • Note the explicit source AND output directories
  • Don't use the <version> we have specified - this is for a custom build snapshot. Use the version you are already using.
  • Don't worry about the dependency - this is to do with Tycho build stuff
Then you copy the resources back to src:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-prod-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src</outputDirectory>
<resources>
<resource>
<directory>src.delomboked</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

  • This copies the delomboked code back to the src directory ready for compilation.
  • Note this will not be a suitable solution if you intend to do a commit back to the main repository as all your code will suddenly become delomboked next time you update :-)
  • We can get away with this only because this is a build server with no commit backs and there will be a fresh checkout that overwrites the copied delomboked code on the next build anyway.
Hope this helps, and as I say I am more than eager to hear better solutions to this.

Chris

Groups group for http://projectlombok.org/
Reply all
Reply to author
Forward
0 new messages