bsideup / jabel

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

Support / example of applying Jabel only to main code on jdk8 and having test code run/compile on jdk13 #36

Open astubbs opened 4 years ago

astubbs commented 4 years ago

As described here: https://stackoverflow.com/questions/1213897/different-maven-compiler-versions-for-test-and-main

An example would be great to include in the instructions.

astubbs commented 4 years ago

I appear to have it working via adding two different executions as per the stack over flow question:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <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>
                </configuration>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <configuration>
                            <!-- jabel setup -->
                            <!-- Make sure we're not using Java 9+ APIs - restricts JDK APIs to those in 8 -->
                            <release>8</release>
                            <annotationProcessors>
                                <annotationProcessor>com.github.bsideup.jabel.JabelJavacProcessor</annotationProcessor>
                                <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
                            </annotationProcessors>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-testCompile</id>
                        <configuration>
                            <release>13</release>
<!-- only run Lombok, don't use Jabel on test classes -->
                            <annotationProcessors>
                              <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
                            </annotationProcessors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
astubbs commented 4 years ago

FYI I've moved away from this now, and am instead compiling everything on 13, targeting 8, but running fail safe multiple times on different jvms.