Question
Does the JetBrains @NotNull annotations work in Maven or not?
Answer
We have a feature request about this: Official @NotNull instrumenter maven and gradle plugin Official @NotNull instrumenter maven and gradle plugin, please vote/star it.
The answer is yes. Below is an example workaround pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>org.example</groupId>
<artifactId>jb_annotations_javac2_mvn</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<intellij.version>203.7148.57</intellij.version>
</properties>
<repositories>
<repository>
<id>jetbrains.releases</id>
<url>https://www.jetbrains.com/intellij-repository/releases</url>
</repository>
<repository>
<id>jetbrains.3rdparty</id>
<url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<path id="j2sp">
<pathelement location="${project.basedir}/src/main/java"/>
</path>
<taskdef name="javac2" classpathref="maven.runtime.classpath" classname="com.intellij.ant.Javac2"/>
<javac2 destdir="${project.basedir}/target/classes">
<src refid="j2sp"/>
</javac2>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
<scope>provided</scope>
</dependency>
<!-- Optional, if you doesn't work with IDEA Swing forms -->
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-gui-forms-rt</artifactId>
<version>${intellij.version}</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-compiler-ant-tasks</artifactId>
<version>${intellij.version}</version>
</dependency>
</dependencies>
</project>
Tested with IDEA 2025.1 and JDK 17, 24.
IDEA Settings: Check Delegate IDE build/run actions to Maven in the menu File | Settings |Build, Execution, Deployment > Build Tools > Maven > Runner options.
You can check the full source code at https://github.com/JackyJetBrains/jb_annotations_javac2_mvn.
Comments
0 comments
Please sign in to leave a comment.