jabel icon indicating copy to clipboard operation
jabel copied to clipboard

Works with Lombok?

Open astubbs opened this issue 5 years ago • 5 comments

Does this work also when you're using Lombok as an active compiler plugin? I have Lombok included as a compiler annotation processor, but I add Jabel and it's annotationProcessors class directive, and the Lombok enhancements don't seem to be active anymore.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>com.google.auto.service</groupId>
                            <artifactId>auto-service</artifactId>
                            <version>${auto-service.version}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <!-- jabel setup-->
                        <path>
                            <groupId>com.github.bsideup.jabel</groupId>
                            <artifactId>jabel-javac-plugin</artifactId>
                            <version>0.2.0</version>
                        </path>
                    </annotationProcessorPaths>
                    <!-- enable language preview features -->
                    <target>13</target>
                    <!-- jabel setup -->
                    <!-- Make sure we're not using Java 9+ APIs -->
                    <release>8</release>
                    <annotationProcessors>
                        <annotationProcessor>com.github.bsideup.jabel.JabelJavacProcessor</annotationProcessor>
                    </annotationProcessors>
                </configuration>
            </plugin>

astubbs avatar Aug 11 '20 19:08 astubbs

Given the popularity of Lombok and maven, including a working example of using jabel with maven would be awesome. I'll keep looking into it. My first clue is this:

https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationProcessors

<annotationProcessors>
Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors discovery process applies.

Which implies to me, that because Jabel seems to require listing it as an explicit annotationProcessor, this causes the the default annotation processors discovery process to be disabled (as it "only applies of annotationProcessors is not set. Apparently... Which might mean that Lombok even though is listed, is not even being run because in this setup it relies on the auto discovery process...

astubbs avatar Aug 12 '20 08:08 astubbs

Boom - gotta love stack overflow: https://stackoverflow.com/questions/11685498/what-is-the-default-annotation-processors-discovery-process

astubbs avatar Aug 12 '20 08:08 astubbs

Ok, tracked down the Lombok annotation processor classes;

  • https://github.com/rzwitserloot/lombok/blob/master/src/launch/lombok/launch/AnnotationProcessor.java
  • https://github.com/rzwitserloot/lombok/blob/master/src/core/lombok/core/AnnotationProcessor.java Defined here: https://github.com/rzwitserloot/lombok/blob/master/src/core9/module-info.java#L38

As the automatic detection method is turned off when any processor is configured explicitly, I add this to my list: <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>

Now m configuration as this the compile passes:

                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                        <!-- jabel setup-->
                        <path>
                            <groupId>com.github.bsideup.jabel</groupId>
                            <artifactId>jabel-javac-plugin</artifactId>
                            <version>0.2.0</version>
                        </path>
                    </annotationProcessorPaths>
                    <!-- enable language preview features -->
                    <target>13</target>
                    <!-- jabel setup -->
                    <!-- Make sure we're not using Java 9+ APIs -->
<!--                    <release>8</release>-->
                    <annotationProcessors>
                        <annotationProcessor>com.github.bsideup.jabel.JabelJavacProcessor</annotationProcessor>
                        <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
                    </annotationProcessors>
                </configuration>

astubbs avatar Aug 12 '20 10:08 astubbs

FYI this does seem to make IDEA complain with

Error:java: Annotation processor 'lombok.launch.AnnotationProcessorHider.AnnotationProcessor' not found and warns; Warning:java: Supported source version 'RELEASE_8' from annotation processor 'com.github.bsideup.jabel.JabelJavacProcessor' less than -source '13'

So added to the override in the IDEA profile by setting the annotationProcessors tree to empty, seems to have relaxed Intellij:

        <profile>
            <id>intellij-idea-only</id>
            <activation>
                <property>
                    <name>idea.maven.embedder.version</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <release>13</release>
                            <compilerArgs>
                                <arg>--enable-preview</arg>
                            </compilerArgs>
                            <annotationProcessors>
                            </annotationProcessors>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

astubbs avatar Aug 12 '20 10:08 astubbs

It works! :-)

See more information here https://github.com/bsideup/jabel/issues/175

magicprinc avatar Mar 13 '23 00:03 magicprinc