AnnotationProcessor (Checker Framework) in Executions Block

34 views Asked by At

I am trying to add the CheckerFrameworks annotation processing to an already existing maven project. In this project, most settings are included in module-specific profiles. If I just add the Checker Framework settings to the maven-compiler-plugin, everything works as expected.

Now, I want to decide, whether or not to inlucde the annotation processing from the Checker Framework in a given build. My idea was to include two </execution> blocks to the maven-compiler-plugin with a skip in them which I can trigger with a parameter.

I tried to add an example pom.xml:

<profile>
    <activation>
        <file>
            <exists>src/main/profiles/activation.profile</exists>
        </file>
    </activation>
    <dependencies>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <version>3.35.0</version>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker</artifactId>
            <version>3.35.0</version>
        </dependency>
        <!-- ... -->
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <configuration>
                                    <id>mvn-compiler-plugin-WITH-CFW</id>
                                    <skip>${!withCFW}</skip>
                                    <release>11</release>
                                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                                    <compilerArguments>
                                        <Xmaxerrs>10000</Xmaxerrs>
                                        <Xmaxwarns>10000</Xmaxwarns>
                                    </compilerArguments>
                                    <annotationProcessorPaths>
                                        <path>
                                            <groupId>org.checkerframework</groupId>
                                            <artifactId>checker</artifactId>
                                            <version>3.35.0</version>
                                        </path>
                                        <!-- ... -->
                                    </annotationProcessorPaths>
                                    <annotationProcessors>
                                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                                    </annotationProcessors>
                                    <compilerArgs>
                                        <arg>-parameters</arg>
                                        <arg>-Awarns</arg>
                                    </compilerArgs>
                                </configuration>
                            </execution>    
                            <execution>
                                <configuration>
                                    <id>mvn-compiler-plugin-WITHOUT-CFW</id>
                                    <skip>${withCFW}</skip>
                                    <release>11</release>
                                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
                                    <annotationProcessorPaths>
                                        <!-- ... -->
                                    </annotationProcessorPaths>
                                    <compilerArgs>
                                        <arg>-parameters</arg>
                                    </compilerArgs>
                                </configuration>
                            </execution>
                        </executions>
                </plugin>
            </plugins>
        </build>
    </dependencies>
</profile>

However, when i tried mvn clean install -DwithCFW=true the annotation processing was not executed - no error response, just no execution. I then reduced the pom to only one <execution> block which included the annotation processing and removed the skip, but this did not work either. I suspect, that my execution block is the problem?


Update:

I found a possible solution to execute the annotation processing within the execution block: I had to specify phase and goal explicitly:

<profile>
    ...
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>compile-with-cfw</id>
                                <goals>
                                   <goal>compile</goal>
                                </goals>
                                <phase>compile</phase>
                                <configuration>
                                    <id>mvn-compiler-plugin-WITH-CFW</id>
                                    <!-- <skip>${!withCFW}</skip> -->
                                    ...
                                </configuration>
                            </execution>    
                            <execution>
                                ...
                            </execution>
                        </executions>
                </plugin>
            ...
</profile>

However, as far as I understood, this should not be necessary, as the goal is bound the correct phase by default? My remaining problem is, how to decide between the two executions, as </skip> seems to be an invalid plugin configuration.

I would greatly appreciate any help in this matter.

Best, Patrick

0

There are 0 answers