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: running before immutables generates source code #5143

Closed
yatesco opened this issue May 25, 2022 · 3 comments
Closed

maven: running before immutables generates source code #5143

yatesco opened this issue May 25, 2022 · 3 comments

Comments

@yatesco
Copy link

yatesco commented May 25, 2022

Hi - this is more a maven question, but googling has failed me. How do I ensure that the checkerframework runs after other things in maven that generate source code?

I am using immutables.org which generates source code into target\generated-sources. The generated source code is referenced in the test code. However, after adding in the three maven profiles the immutables logic is no longer run which causes the code not to compile.

If I comment out the three build profiles then mvn clean package works. If I leave the three build profiles in then mvn clean package fails because it can't find the generated source code and target\generated-sources is empty.

I've tried adding the org.immutables dependency in the checkerframework's profile's annotationProcessorPaths but that still didn't generate the source code.

Do you have any pointers I could chase here? Thanks!

@yatesco
Copy link
Author

yatesco commented May 25, 2022

I think I've fixed this by adding the org.immutables.value.internal.$processor$.$Processor to the list of annotationProcessors in the checkerframework build profile:

<profile>
            <id>checkerframework</id>
            <activation>
                <jdk>[1.8,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <fork>true</fork> <!-- Must fork or else JVM arguments are ignored. -->
                            <compilerArguments>
                                <Xmaxerrs>10000</Xmaxerrs>
                                <Xmaxwarns>10000</Xmaxwarns>
                            </compilerArguments>
                            <annotationProcessorPaths>
                                <path>
                                    <groupId>org.checkerframework</groupId>
                                    <artifactId>checker</artifactId>
                                    <version>3.22.0</version>
                                </path>
                            </annotationProcessorPaths>
                            <annotationProcessors>
                                <!-- ***** THIS IS THE MAGIC ****** -->
                                <annotationProcessor>org.immutables.value.internal.$processor$.$Processor
                                <!-- Add all the checkers you want to enable here -->
                                </annotationProcessor>
                                <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker
                                </annotationProcessor>
                            </annotationProcessors>
                            <compilerArgs>
                                <!-- <arg>-Awarns</arg> --> <!-- -Awarns turns type-checking errors into warnings. -->
                            </compilerArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <dependency>
                    <groupId>org.checkerframework</groupId>
                    <artifactId>checker</artifactId>
                    <version>3.22.0</version>
                </dependency>
            </dependencies>
        </profile>

I'm at the "throw random XML lines until the errors go away" so I'll leave this open in the hope somebody confirms/upgrades these instructions.

@msridhar
Copy link
Contributor

msridhar commented May 25, 2022

@yatesco I think the issue here is likely that the immutables processor normally runs using "auto-discovery", where just placing it in the processor path causes it to run by default. Auto-discovery gets disabled if you add any explicit -processor arguments (or <annotationProcessor> options in Maven) in your config. This can be fixed either by explicitly listing every annotation processor you want to run (I think this is your current fix), or by running the Checker Framework using auto-discovery, as documented here:

https://checkerframework.org/manual/#checker-auto-discovery

Let us know if that makes sense / solves your problem.

@yatesco
Copy link
Author

yatesco commented May 25, 2022

Thanks @msridhar - yes, this worked - thank you. Closing.

@yatesco yatesco closed this as completed May 25, 2022
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