如何在pom.xml上运行maven-jdeps-plugin?

时间:2016-02-04 10:05:56

标签: java maven java-9 jdeps

在我的 boolean isArrValid = true; String pattern = "^[a-zA-Z0-9]*$"; if (lotNumArrList != null && lotNumArrList.size() > 0) { for (String str : lotNumArrList) { if (str == null || !str.matches(pattern)) { isArrValid = false; break; } } } else { isArrValid = false; } if(isArrValid) { //Your action } 我添加了maven-jdeps-plugin:

pom.xml

但是当我使用JDK 8和maven 3.3.3运行时, jdeps插件不会进行任何检查

<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>

额外信息:

$ 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 ---

2 个答案:

答案 0 :(得分:1)

因为问题是用Java-9标记的。 maven jdeps plugin版本3.1.0正式released recently,声称也是compatible with jdk9

@khmarbaise在评论中指出的官方usage page of the plugin,将实施说明如下:

<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>

,其中

  

如果检测到内部API有任何用法,则构建将停止   并失败。

可以使用标记failOnWarning配置,其默认值设置为true

答案 1 :(得分:0)

正如Di Matteo在评论中所说,这个配置修复了它:

<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>

直接<goals>下的<plugin>使用deprecated, doesn't work,但不会快速失败......