Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: unknown enum constant Status.STABLE

In the quest to solve this and somehow that, I was trying out to create packages to subdivide main and test classes and then to make use of compiler with added modules to execute the unit-tests. Not a very good way agreed, but just a hypothetical structure for now.

enter image description here

Few open questions as I proceeded further were:-

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

Q. Note that it brings along the opentest4j-1.0.0.jar to the lib/ folder. Why is that so, what is the other jar used for?

  • Add the classes and generate some tests method correspondingly.

  • Compile the sample project (shared just to draw a picture of the directory structure in use) using the command

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

    Results into warnings as -

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 usage of junit-jupiter suspicious since if I comment out the code using JUnit and execute the same command, things seem to be working fine.

Libraries/Tools used if that might matter:-

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

Q. What could be a probable cause to such a warning? Moreover, I am unable to find the API.Status in my project and outside the project classes as well.

like image 316
Naman Avatar asked Oct 12 '17 05:10

Naman


2 Answers

The compilation warning can simply be ignored. Moreover, it won't be appearing anymore starting with the version 5.1.0 (currently in development). It is all explained in Release Notes:

In 5.0.1, all artifacts were changed to have an optional instead of a mandatory dependency on the @API Guardian JAR in their published Maven POMs. However, although the Java compiler should ignore missing annotation types, a lot of users have reported that compiling tests without having the @API Guardian JAR on the classpath results in warnings emitted by 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 has decided to make the dependency to the @API Guardian JAR mandatory again.

For reference also see:

  • Remove compile dependency on apiguardian-api in Maven POMs
  • Reintroduce compile dependency on apiguardian-api in Maven POMs
like image 99
ᄂ ᄀ Avatar answered Nov 16 '22 03:11

ᄂ ᄀ


1) opentest4j

opentest4j is a transitive dependency of junit-jupiter-api. See the 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 enum constant Status.STABLE

You need to add following dependency: apiguardian-api.

For example in Gradle, you can do it 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, dependency is build-tool-independent, so you can do it in plain IDE without Gradle, or Maven.

like image 33
Vít Kotačka Avatar answered Nov 16 '22 02:11

Vít Kotačka