71

I have a big Maven project that uses the PMD plugin for code quality checks.

since I started using the PMD plugin i get the following warning message:

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

I googled and found that i need to implement the JXR plugin.

So I added the following to the main pom.xml file.

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

It doesn't really change anything.

Any ideas what I need to change in order to resolve this warning message?

output of 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"

thanks!

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
ufk
  • 30,912
  • 70
  • 235
  • 386

4 Answers4

93

You should add the maven-jxr-plugin to the reportingPlugin section.

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

Re run it and enjoy.

BTW, maybe you'll need to run once the jxr:jxr goal to first generate some file that will be used by pmd.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
poussma
  • 7,033
  • 3
  • 43
  • 68
  • 3
    ok.. i add that plugin under and it seems to solve the issue. thanks! – ufk Aug 21 '12 at 11:10
  • 1
    Likely to know any usage of this plugin other than exposing source code of your project? – srk Jan 09 '19 at 14:25
  • 3
    As of 26th Oct 2020 the current version of JXR Maven plugin is 3.0.0 see https://maven.apache.org/jxr/maven-jxr-plugin/ DO NOT blindly copy&paste stuff from SO to your projects – user1053510 Oct 26 '20 at 09:50
65

Mind there is also the ability to disable the xref feature by adding

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

to the maven-pmd-plugin plugin. This resolves the warning without making the build even longer due to running an additional reporting plugin. E.g. if you run your builds in Jenkins, the Jenkins PMD plugin can take care of relating PMD warnings to source code, there is no need to run another Maven plugin for this.

rec
  • 10,340
  • 3
  • 29
  • 43
1

You should add the maven-jxr-plugin and run the jxr:jxr goal before the site lifecycle if the maven-jxr-plugin is added as a plugin like in your case:
clean jxr:jxr site

Otherwise you should add it as a report if you want it to work with mvn site. Take a look at the JXR Usage Documentation : JXR Usage

Mehdi
  • 1,494
  • 5
  • 33
  • 53
0

It is way easier to configure it this way and not tie it to the site phase.

Then, it is as simple as mvn test.

<plugins>
  <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>
  </plugin>
</plugins>
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
djangofan
  • 28,471
  • 61
  • 196
  • 289