How do I run maven-jdeps-plugin on a pom.xml?

3.9k Views Asked by At

In my pom.xml I've added the maven-jdeps-plugin:

<project ...>
  <groupId>org.optaplanner</groupId>
  <artifactId>optaplanner-examples</artifactId>
  <!-- packaging is the default, so "jar" -->
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jdeps-plugin</artifactId>
        <version>3.0.0</version>
        <goals>
          <goal>jdkinternals</goal>
          <goal>test-jdkinternals</goal>
        </goals>
      </plugin>
    </plugins>
  </build>
</project>

but when I run this with JDK 8 and maven 3.3.3, the jdeps plugin does not do any checks:

$ mvn clean install -DskipTests | grep plugin
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ optaplanner-examples ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-plugin-versions) @ optaplanner-examples ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-java-version) @ optaplanner-examples ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-maven-version) @ optaplanner-examples ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (ban-uberjars) @ optaplanner-examples ---
[INFO] --- maven-checkstyle-plugin:2.15:check (validate) @ optaplanner-examples ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (no-managed-deps) @ optaplanner-examples ---
[INFO] --- buildnumber-maven-plugin:1.3:create (get-scm-revision) @ optaplanner-examples ---
[INFO] --- build-helper-maven-plugin:1.9.1:add-source (default) @ optaplanner-examples ---
[INFO] --- build-helper-maven-plugin:1.9.1:parse-version (default) @ optaplanner-examples ---
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ optaplanner-examples ---
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ optaplanner-examples ---
[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-direct-dependencies) @ optaplanner-examples ---
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ optaplanner-examples ---
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ optaplanner-examples ---
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ optaplanner-examples ---
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ optaplanner-examples ---
[INFO] --- maven-jar-plugin:2.6:test-jar (test-jar) @ optaplanner-examples ---
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ optaplanner-examples ---
[INFO] --- maven-source-plugin:2.4:test-jar-no-fork (attach-test-sources) @ optaplanner-examples ---
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default) @ optaplanner-examples ---
[INFO] --- maven-failsafe-plugin:2.18.1:verify (default) @ optaplanner-examples ---
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ optaplanner-examples ---

Extra info:

$ echo $JAVA_HOME
/usr/lib/jvm/java-openjdk
$ /usr/lib/jvm/java-openjdk/bin/java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
2

There are 2 best solutions below

0
On

Since the question was tagged with Java-9. The maven jdeps plugin version 3.1.0 was officially released recently and is claimed to be compatible with jdk9 as well.

The official usage page of the plugin as pointed out in comments by @khmarbaise as well, states the implementation as:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jdeps-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
      <execution>
        <goals>
          <goal>jdkinternals</goal> <!-- verify main classes -->
          <goal>test-jdkinternals</goal> <!-- verify test classes -->
        </goals>
      </execution>
    </executions>
    <configuration>
      ...
    </configuration>
</plugin>

wherein

If there is any usage detected of an internal API, the build will stop and fail.

which can be configured using a flag failOnWarning which has a default value set as true.

0
On

As Di Matteo suggested in the comments, this config fixes it:

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jdeps-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <goals>
          <goal>jdkinternals</goal>
          <goal>test-jdkinternals</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

The usage of <goals> directly under <plugin> is deprecated, doesn't work but doesn't fail fast...