Warning: unknown enum constant Status.STABLE

In search of a solution to this and somehow that , I tried to create packages to separate main and test , and then use the compiler with added modules to perform unit tests. Not a very good way, but only a hypothetical structure.

enter image description here

A few open questions that I continued were as follows: -

  • Add a module based on JDK9 to the project.
  • Add JUnit5 to the classpath using the IntelliJ shortcut. (lib folder) [ junit-jupiter-api-5.0.0.jar ]

Q. Note that it brings opentest4j-1.0.0.jar to the lib / folder. Why is this, why is another bank used?

  • Add classes and generate some test method accordingly.

  • Compile a sample project (share simply to draw an image of the directory structure used) with the command

     javac --module-path lib -d "target" $(find src -name "*.java") 

    Results in warnings like -

 warning: unknown enum constant Status.STABLE reason: class file for org.apiguardian.api.API$Status not found warning: unknown enum constant Status.STABLE 2 warnings 

Note : -

I find the use of junit-jupiter suspicious, because if I comment on the code using JUnit and execute the same command, everything looks fine.

Libraries / Tools , if it may matter: -

  • junit-jupiter-api-5.0.0 with
  • Java Version "9" (build 9+181)
  • IntelliJ 2017.2.5

Q. What could be the likely cause of such a warning? Moreover, I can not find the API.Status in my project and outside the project classes.

+8
java unit-testing java-9 junit5
source share
2 answers

1) opentest4j

opentest4j is a transitive dependency of junit-jupiter-api . See dependency graph:

 +--- org.junit.jupiter:junit-jupiter-api:5.0.1 +--- org.opentest4j:opentest4j:1.0.0 \--- org.junit.platform:junit-platform-commons:1.0.1 

2) unknown constant enum Status.STABLE

You need to add the following dependency: apiguardian-api .

For example, in Gradle, you can do this via:

 dependencies { testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.1' testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.1' testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0' } 

But overall, the dependency is build independent, so you can do it in a simple IDE without Gradle or Maven.

+3
source share

The compilation warning can simply be ignored. Moreover, it will no longer be displayed since version 5.1.0 (currently under development). Everything is explained in the Release Notes :

In 5.0.1, all artifacts were changed to have an optional, not mandatory dependency on the JAPI Guardian JAR in the published Maven POM. However, while the Java compiler should ignore missing annotation types, many users have reported that compiling tests without using the JAPI Guardian JAR on the classpath leads to warnings emanating from javac that look like this:

 warning: unknown enum constant Status.STABLE reason: class file for org.apiguardian.api.API$Status not found 

To avoid confusion, the JUnit team decided to re-enable the JAPI Guardian JAR dependency.

For reference, see also:

+1
source share

All Articles