【问题标题】:Unable to locate Source XRef to link to无法找到要链接到的源外部参照
【发布时间】:2012-08-15 19:37:02
【问题描述】:

我有一个使用 pmd 插件进行代码质量检查的大型 maven 项目。

自从我开始使用 pmd 插件后,我收到以下警告消息:

[WARNING] Unable to locate Source XRef to link to - DISABLED

我google了一下,发现需要实现jxr插件。

所以我将以下内容添加到主 pom.xml 文件中的 build 属性中。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jxr-plugin</artifactId>
    <version>2.3</version>
  </plugin>

welp 它并没有真正改变任何东西。

有什么想法我需要实施以解决此警告消息?

mvn -version的输出

Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
Maven home: /usr/share/maven-bin-3.0
Java version: 1.7.0_05, vendor: Oracle Corporation
Java home: /usr/lib64/icedtea7/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "3.5.2-gentoo", arch: "amd64", family: "unix"

谢谢!

【问题讨论】:

    标签: java maven maven-3 pmd


    【解决方案1】:

    您应该将maven-jxr-plugin 添加到reportingPlugin 部分。

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>2.3</version>
            </plugin>
        </plugins>
    </reporting>
    

    重新运行并享受。

    顺便说一句,也许您需要运行一次 jxr:jxr 目标才能首先生成一些将由 pmd 使用的文件。

    【讨论】:

    • ok.. 我在 下添加了那个插件,它似乎解决了这个问题。谢谢!
    • 除了暴露你的项目的源代码之外,可能知道这个插件的任何用法吗?
    • 截至 2020 年 10 月 26 日,JXR Maven 插件的当前版本为 3.0.0,请参阅 maven.apache.org/jxr/maven-jxr-plugin 不要盲目地将 SO 中的内容复制粘贴到您的项目中
    【解决方案2】:

    请注意,还可以通过添加禁用外部参照功能

    <configuration>
      <linkXRef>false</linkXRef>
    </configuration>
    

    到 maven-pmd-plugin 插件。由于运行了额外的报告插件,这解决了警告,而不会使构建时间更长。例如。如果您在 Jenkins 中运行构建,Jenkins PMD 插件可以负责将 PMD 警告与源代码相关联,无需为此运行另一个 Maven 插件。

    【讨论】:

    • 添加 false 也会消除警告。
    【解决方案3】:

    如果 maven-jxr-plugin 被添加为插件,就像您的情况一样,您应该添加 maven-jxr-plugin 并在 site 生命周期之前运行 jxr:jxr 目标:
    clean jxr:jxr site

    否则,如果您希望它与mvn site 一起使用,则应将其添加为报告。查看 JXR 使用文档: JXR Usage

    【讨论】:

      【解决方案4】:

      以这种方式配置它更容易,而不是将其绑定到站点阶段。

      那么,就这么简单mvn test

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
            <dependencies>
              <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-surefire-provider</artifactId>
                <version>1.2.0</version>
              </dependency>
              <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>${junit.jupiter.version}</version>
              </dependency>
            </dependencies>
            <configuration>
            <testSourceDirectory>src/test/java</testSourceDirectory>
            <includes>
              <include>com.whatever.suite.*</include>
            </includes>
            <systemPropertyVariables>
              <selenide.remote>${grid.hub}</selenide.remote>
            </systemPropertyVariables>
            <trimStackTrace>false</trimStackTrace>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-report-plugin</artifactId>
          <version>${maven-surefire-plugin.version}</version>
          <configuration>
            <outputDirectory>target/surefire-reports</outputDirectory>
            <linkXRef>false</linkXRef>
          </configuration>
          <executions>
            <execution>
              <id>during-tests</id>
              <phase>test</phase>
              <goals>
                <goal>report</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
      

      【讨论】:

        猜你喜欢
        • 2010-12-30
        • 1970-01-01
        • 1970-01-01
        • 2016-08-16
        • 1970-01-01
        • 2014-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多