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

Need a maven project example which integrates the project lombok. #3358

Closed
sincebyte opened this issue Jun 7, 2020 · 1 comment
Closed

Comments

@sincebyte
Copy link

sincebyte commented Jun 7, 2020

Fistly I am very grateful for the checker-framework project.
It is a great work which could liberate me from the nullpointer exception in java.
However, the examples listed in this respository(checker-framework/docs/examples/) do not contain a maven project which integrates the project lombok,so could you kindly add an maven project for more users like me.
your reply is highly appreciated.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
       <parent>
        <groupId>...</groupId>
        <artifactId>...</artifactId>
        <version>0.2.0-SNAPSHOT</version>
    </parent>
    <packaging>jar</packaging>
    <artifactId>...</artifactId>
    <description> </description>

    <properties>
        <encoding>UTF-8</encoding>
        <maven.deploy.skip>true</maven.deploy.skip>
        <maven.tesk.skip>true</maven.tesk.skip>
        <checker-framework.version>2.3.2</checker-framework.version>
        <errorProneJavac>${com.google.errorprone:javac:jar}</errorProneJavac>
        <project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <version>${checker-framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>compiler</artifactId>
            <version>${checker-framework.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.errorprone</groupId>
            <artifactId>javac</artifactId>
            <version>9+181-r4173-1</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <!-- This plugin will set properties values using dependency information -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <fork>true</fork>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showWarnings>true</showWarnings>
                    <verbose>true</verbose>
                    <annotationProcessorPaths>
                        <path>
                        <groupId>org.checkerframework</groupId>
                        <artifactId>checker</artifactId>
                        <version>${checker-framework.version}</version>
                        </path>
                        <path>
                          <groupId>your.qual.group</groupId>
                          <artifactId>your-qual-artifact</artifactId>
                          <version>your-qual-artifact-version</version>
                        </path>
                    </annotationProcessorPaths>
                    <annotationProcessors>
                        <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                        <annotationProcessor>org.checkerframework.checker.nullness.qual.NonNull</annotationProcessor>
                    </annotationProcessors>
                    <compilerArgs>
                        <arg>-J-Xbootclasspath/p:${errorProneJavac}</arg>
                        <arg>-Alint</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Test.java

    /**
     * test checker framework
     */
    private void test(){
        @NonNull
        String str = null;
        str.isEmpty();
        log.info(str);
    }

execute : mvn clean compile

The output is getter and setter function symbol which generate by lombok can't be found ,that maybe means lombok not work with checker framework.
How to fix it?

@mernst
Copy link
Member

mernst commented Jun 7, 2020

Here are three possibilities for you:

  • You could use the Gradle build system. There is a Gradle plugin that lets you run both the Checker Framework and Lombok.
  • You could write a Maven plugin, copying the logic from the Gradle plugin.
  • You could copy the logic from the Gradle plugin to your Maven build file.

If you choose the second or third possibility, we would be happy to accept a pull request that shows how to use the Checker Framework and Lombok at the same time, using Maven. Thanks in advance for your contribution.

@mernst mernst closed this as completed Jun 7, 2020
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