【问题标题】:How do I run maven-jdeps-plugin on a pom.xml?如何在 pom.xml 上运行 maven-jdeps-plugin?
【发布时间】:2016-02-04 10:05:55
【问题描述】:

在我的pom.xml 中,我添加了 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>

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

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

额外信息:

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

【问题讨论】:

  • 你的 sn-p 正确吗?目标不能存在于 maven 插件的 xml 结构中,它们应该是执行/执行的一部分
  • 我可以发誓他们可以直接嵌套在 maven 中......愚蠢的错误。可惜 Maven 并没有很快失败,只是忽略了它。
  • 这可能是插件没有被执行的原因,你需要一个执行来指定目标作为构建的一部分

标签: java maven java-9 jdeps


【解决方案1】:

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

@khmarbaise 在 cmets 中也指出,官方 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

【讨论】:

    【解决方案2】:

    正如 Di Matteo 在 cmets 中建议的那样,这个配置修复了它:

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

    &lt;plugin&gt; 直接下&lt;goals&gt; 的用法是deprecated, doesn't work 但不会很快失败...

    【讨论】:

      猜你喜欢
      • 2021-09-22
      • 2014-07-09
      • 2019-05-21
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多