Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven Compilation issue #1050

Open
merric opened this issue Mar 16, 2016 · 4 comments
Open

Maven Compilation issue #1050

merric opened this issue Mar 16, 2016 · 4 comments

Comments

@merric
Copy link

merric commented Mar 16, 2016

I've riffled through the internet today trying to make Lombok work with the Maven compiler plugin and haven't found a solution that doesn't require maintain a new source code flow.

So far I've tried:

Using what is suggested in the FAQ, nothing. I have pulled the latest lombak jar in as a dependency:

       <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.8</version>
            <scope>provided</scope>
        </dependency>

Unfortunately this does nothing to fix compilation issues according to maven. I will note that the FAQ shows that it only works with Java 6, but many other release notes show that lombok does work with java 8. I need at least java 7 for this project and likely java 8 for using it in any others.

Next, I attempted to use the annotation processor on the compiler plugin with both:

    <annotationProcessor>lombok.core.AnnotationProcessorr</annotationProcessor>

and

<annotationProcessor>lombok.launch.AnnotationProcessorxHider$AnnotationProcessor</annotationProcessor>

Both come up as not found when running. This is my best build where it still doesn't work:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <annotationProcessors>
                        <annotationProcessor>lombok.launch.AnnotationProcessorxHider$AnnotationProcessor</annotationProcessor>
                    </annotationProcessors>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.2.4</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- source output directory -->
                            <!--<outputDirectory>${generated-java-source}</outputDirectory>-->
                            <outputDirectory>/target/generated-sources</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <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>${generated-java-source}</source>-->
                                <source>/target/generated-sources</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The only thing that worked was suggested in the faq. Use the lombok maven plugin to generate source for the entire project and then relocate the source directory for maven to that generated source directory.

I feel that that's a bad work flow though as every other plugin will need to insure they work with that directory and not have conflicts with the source directory being generated sources.

Am I missing something big here. I am using Intellij 15 on Windows 7. I have the lombok intellij plugin and I can compile my sources through command line and intellij, but not through maven on the command line or intellij's maven plugin.

@trumpetinc
Copy link

I'm running into this as well. Java 8, Lombok 1.16.8. Inside Eclipse, everything works properly, but when we do maven build, it fails. In our particular case, we get "error: cannot find symbol" errors on the lombok generated methods we are calling.

I don't think it matters, but the end result is a hard failure of the build (FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE(112)).

Dropping back to 1.14.8 resolves the issue (Except now we can't use all the awesome 1.16 goodies).

@merric
Copy link
Author

merric commented Mar 17, 2016

This is what I landed on in the meantime to get it to work. I did have to set Intellij to exclude the target directory from compile time so that it ignores the Delombok stuff when it does a compile scan.

    <build>
        <sourceDirectory>target/generated-sources</sourceDirectory>
        <!--<testSourceDirectory>target/generated-test-sources/delombok</testSourceDirectory>-->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.16.8.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>delombok</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <addOutputDirectory>false</addOutputDirectory>
                    <sourceDirectory>src/main/java</sourceDirectory>
                    <outputDirectory>target/generated-sources</outputDirectory>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

@trumpetinc
Copy link

FYI - the above pom changes do not fix the issue for me in Eclipse... I still get the 'cannot find symbol' errors.

The above also triggers a pom error in the eclipse maven plugin:

"Execution default of goal org.projectlombok:lombok-maven-plugin:1.16.8.0:delombok failed: An API incompatibility was encountered while executing org.projectlombok:lombok-maven-plugin:1.16.8.0:delombok: java.lang.IllegalAccessError: lombok/launch/Main"

no idea what's going on there, but it appears that delombok is also not working for me...

@trumpetinc
Copy link

I took another stab at this, and I have it working now. Capturing it here in case anyone else runs into this in Eclipse.

So the entry for delombok works great for standalone maven. But it causes problems for the Maven 2 Eclipse lifecycle integration. So the error I was seeing was just M2E saying that it didn't know what to do with that particular lifecycle step. All I needed to do was add explicit instructions that m2e should ignroe that step (after all, the only reason we have it at all is to get maven to build outside of Eclipse). This is big and scary, but not super complicated (here's the documentation for adding this sort of exclusion: https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html ):

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>

                        <pluginExecutions>
                            <pluginExecution>

                                <pluginExecutionFilter>
                                    <groupId>org.projectlombok</groupId>
                                    <artifactId>lombok-maven-plugin</artifactId>
                                    <versionRange>[1,)</versionRange>
                                    <goals>
                                        <goal>delombok</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>

                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

Once I did that, everything builds properly inside Eclipse, and I can do my Maven builds with 1.16.8. Super handy. Clearly there is still a bug in Lombok related to building with standalone maven, but at least there's a very reasonable workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants