bsideup / jabel

Jabel - unlock Javac 9+ syntax when targeting Java 8
Apache License 2.0
803 stars 47 forks source link

Works with Lombok? #35

Open astubbs opened 4 years ago

astubbs commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

astubbs commented 4 years ago

Ok, tracked down the Lombok annotation processor classes;

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 commented 4 years ago

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>
magicprinc commented 1 year ago

It works! :-)

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