--- name: jspecify-skill description: > Use this skill when asked to perform any of the following actions in a Java project: - To add jspecify support - To prevent NullPointerExceptions - To better handle Nullability This skill will add jspecify dependency, configure Maven or Gradle build to automatically use jspecify for checking Nullability issues. --- Jspecify provides a set of annotations to explicitly declare the nullness expectations of the Java code. ## Add jSpecify support in Maven projects If you are using Maven, then add the jspecify dependency in `pom.xml`. In `pom.xml`, update or add the `maven-compiler-plugin`, to include the following configuration. ```xml org.jspecify jspecify 1.0.0 org.apache.maven.plugins maven-compiler-plugin 3.14.1 25 UTF-8 true -XDcompilePolicy=simple --should-stop=ifError=FLOW -Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked -XepOpt:NullAway:JSpecifyMode=true -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED com.google.errorprone error_prone_core 2.42.0 com.uber.nullaway nullaway 0.12.12 ``` ## Add jSpecify support in Gradle projects If you are using Gradle, then add the jspecify dependency. In `build.gradle` or `build.gradle.kts`, update or add the following jspecify configuration. ```groovy plugins { id("net.ltgt.errorprone") version "4.3.0" } tasks.withType(JavaCompile).configureEach { options.errorprone { disableAllChecks = true // Other error prone checks are disabled option("NullAway:OnlyNullMarked", "true") // Enable nullness checks only in null-marked code error("NullAway") // bump checks from warnings (default) to errors option("NullAway:JSpecifyMode", "true") // https://github.com/uber/NullAway/wiki/JSpecify-Support } // Keep a JDK 25 baseline options.release = 25 } dependencies { implementation("org.jspecify:jspecify:1.0.0") errorprone("com.google.errorprone:error_prone_core:2.42.0") errorprone("com.uber.nullaway:nullaway:0.12.12") } ``` ## Add @NullMarked to package-info.java files In every java package under the application main source code (`src/main/java`), create `package-info.java` if not exists already, and add the `@NullMarked` annotation as follows: ```java @org.jspecify.annotations.NullMarked package com.mycompnay.myproject; ``` If `package-info.java` file already exists, update the file to add `@org.jspecify.annotations.NullMarked` annotation. DO NOT REMOVE ANY OTHER EXISTING CODE IN `package-info.java` FILE. ## Verify jSpecify support If python is installed, after adding the jSpecify support, run `scripts/verify_nullmarked.py` to check if all non-empty packages has `package-info.java` file or not.