Unable to locate Source XRef to link to - java

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!

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.

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.

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

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>

Related

Can't link to JDK10 in Javadoc comments

After upgrading from Java 9 to 10, links to the JDK no longer work when generating documentation with the Javadoc tool (e.g., for a file importing java.util.Optional, {#link Optional} renders as Optional instead of as Optional; same issue with #see, #param, #return, and anywhere else you normally see Javadoc links).
I have a simple modularized project, and I'm using Maven with the Javadoc plugin (source and target options set to 10 in the configuration section for the compiler plugin). My understanding is that by default it passes -link https://docs.oracle.com/javase/10/docs/api/ to the Javadoc tool. It's also my understanding that, historically, the Javadoc tool expected a text file named package-list to be present at the URL where it was told to find external docs. Java 8 has one. Java 9 has one. Java 10 does not (404 error). Apparently, the Javadoc tool now outputs a text file named element-list instead of package-list for modularized projects, but it seems like that isn't provided either (nor for Java 9, but it is available for early-access builds of Java 11).
Generating Javadoc through IntelliJ with the option Link to JDK documentation enabled produces the same result. It says it's passing -link https://docs.oracle.com/javase/10/docs/api/ to javadoc.exe, and it reports javadoc: error - Error fetching URL: https://docs.oracle.com/javase/10/docs/api/. Despite the error, it does output the Javadoc, but as with Maven, no JDK links are present.
How is this supposed to work? Did Oracle screw up when they put the JDK docs online?
The relevant bits of my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!--update dependency for Java 10 compatibility-->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Output of mvn -version:
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T12:49:05-07:00)
Maven home: C:\Program Files\apache-maven-3.5.3\bin\..
Java version: 10, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-10
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
There are two parts to this.
In JDK 10, the format and name of the file have changed, to better support modules. The new name is "element-list" and the change in format allows the javadoc tool to know what modules are present in an API as well as what packages.
The copy of the API that is posted at https://docs.oracle.com/javase/10/docs/api/overview-summary.html seems to be blocking the "element-list" file, giving a 404. That needs to be investigated and fixed.
Note that you will need to use a JDK 10 version of javadoc to point to the JDK 10 API. The latest version of the tool understands both element-list (for docs about modules) and package-list (for docs about packages (i.e. no modules)).
My workaround for the moment is to point javadoc.exe at a local package-list using the offlineLinks option of the Maven Javadoc plugin (which corresponds to the linkoffline option of the Javadoc tool). I added the following to the configuration section for the plugin:
<detectJavaApiLink>false</detectJavaApiLink>
<offlineLinks>
<offlineLink>
<url>https://docs.oracle.com/javase/${maven.compiler.release}/docs/api/</url>
<location>${project.basedir}</location>
</offlineLink>
</offlineLinks>
And I added <maven.compiler.release>10</maven.compiler.release> to the properties section of my pom.xml so that I could use ${maven.compiler.release} in the value for the url. (That makes the source and target compiler options redundant, but IntelliJ doesn't seem to understand release when importing Maven projects, so I kept them.)
I created a text file named package-list (no file extension) and put it in the root directory of the project (hence ${project.basedir} for the location, which is where it will look for package-list). That file looks like this:
java.lang
java.util
java.util.concurrent
java.util.function
java.util.stream
It only needs the packages that you're trying to link to. I also tried naming the file element-list and following the format that javadoc.exe uses for modularized projects, like so:
module:java.base
java.lang
java.util
java.util.concurrent
java.util.function
java.util.stream
But that didn't work (Javadoc successfully generated, but no JDK links, as before). It complained that it couldn't find package-list.
So, once again, the relevant bits of the pom.xml:
<properties>
<maven.compiler.release>10</maven.compiler.release> <!--release makes source and target-->
<maven.compiler.source>10</maven.compiler.source> <!--redundant, but IntelliJ doesn't-->
<maven.compiler.target>10</maven.compiler.target> <!--use release when importing-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!--update dependency for Java 10 compatibility-->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<detectJavaApiLink>false</detectJavaApiLink>
<offlineLinks>
<offlineLink>
<url>https://docs.oracle.com/javase/${maven.compiler.release}/docs/api/</url>
<location>${project.basedir}</location>
</offlineLink>
</offlineLinks>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
...Maven committer here.
Appropriate bits have been added to Maven Javadoc Plugin in master already, but that won't help due to a bug in javadoc(1) in Java 11. See MJAVADOC-561 for details. The broken links can only be fixed by Oracle.
Edit: The fix is scheduled for Java 11.0.2 by Oracle.

Having JAVA_HOME inconsistency issue with maven

I am on the verge of releasing a project but it seem JAVA_HOME is been inconsistent. Maybe it's been overridden somewhere else? I am using ubuntu 14.04 and I have openjdk-7, java-7-oracle, java-8-oracle. Default java was set using update-java-alternatives
java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
mvn -version gives the following output
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T17:37:52+00:00)
Maven home: /usr/share/maven3
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-39-generic", arch: "amd64", family: "unix"
But when doing mvn release:prepare, below is what I see:
[INFO] Not generating release POMs
[INFO] Executing goals 'clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] Error: JAVA_HOME is not defined correctly.
[INFO] We cannot execute /usr/lib/jvm/java-8-oracle/bin/java/bin/java
It looks like the java executor is being looked for in the wrong folder : /java/bin/java. I have tried changing java home to /usr/lib/jvm/java-8-orable/bin but it broke mvn-version check.
How to fix this? Thanks for reading
I can't find here to fix that. Has anyone encountered anything similar?
EDIT 1:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<excludes>
<exclude>**/*ITest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<preparationGoals>clean verify</preparationGoals>
<tagBase>https://xxxx/svn/projectname/tags</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
I have switched to java-7-oracle and still no chance:
[INFO] Executing goals 'clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] Error: JAVA_HOME is not defined correctly.
[INFO] We cannot execute /usr/lib/jvm/java-7-oracle/bin/java/bin/java
EDIT 2:
Dear down voters, I am not asking for help about how to set Java Home. It's been set to
/usr/lib/jvm/java-8-oracle
Then to the following when I tried running same thing with java 7
/usr/lib/jvm/java-7-oracle
This is set in /etc/profile.d/jdk.sh by webup8 script
export J2SDKDIR=/usr/lib/jvm/java-7-oracle
export J2REDIR=/usr/lib/jvm/java-7-oracle/jre
export PATH=$PATH:/usr/lib/jvm/java-7-oracle/bin:/usr/lib/jvm/java-7-oracle/db/bin:/usr/lib/jvm/java-7-oracle/jre/bin
export JAVA_HOME=/usr/lib/jvm/java-7-oracle
export DERBY_HOME=/usr/lib/jvm/java-7-oracle/db
EDIT 3
I have switched to openjdk 7 , edited the jdk.sh to reflect this export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64 and the error went. I run to other famous issues (permission issues to tags folder. weird) . So it's not related to the maven itself I guess. But this is weird that it works fine for openjdk ...
JAVA_HOME must point to jre, not jdk. Then set :
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
Creating a file .mavenrc on my home folder and adding the code below solved the problem for me. (Ubuntu 14.10, Maven 3.2.1)
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
Another workaround:
export JAVACMD=$JAVA_HOME/bin/java
setting /usr/lib/jvm/java ⇒ /usr/java/jdk1.7.0_45 did not work for me
I spend quite some time to tackle similar error. It looks like package manager might create mess in Java installations. Path to Java is sometimes hardcoded in bash files. I found one in /etc/profile.d/jdk.sh. It just overrides your settings. Another fix/workaround for that is to update symlink, in my case it was /usr/lib/jvm/java ⇒ /usr/java/jdk1.7.0_45. Try to look for java/bin text in all bash files.
in super user privilege on your terminal open
vi etc/environment
on opened file add JAVA_HOME path
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/"
Hope you set the JAVA_HOME
check if your JAVA_HOME is set using command
echo $JAVA_HOME
I used OpenJDK as default java , updated JAVA_HOME in /etc/environment and all the issues went. Thanks for all your effort helping me through this
I had the same problem. My workaround was:
cd /usr/lib/jvm/java-8-oracle/jre/bin
sudo ln -s /usr/lib/jvm/java-8-oracle/bin/java java

Maven: compiling and testing on different source levels

I am currently working on a project which will run on an embedded device. The device runs a Java ME JRE (comparable to Java 1.4).
Because of this maven is configured to compile for source & target level 1.4.
Is it possible to run the maven test phase on a different source/target level? Because this way I could use Mockito for unit-testing.
The source and target versions can be set separately for the compile and testCompile goals of the maven compiler plugin. You can change the settings either by defining properties in your pom:
<properties>
<maven.compiler.source>1.4</maven.compiler.source>
<maven.compiler.target>1.4</maven.compiler.target>
<maven.compiler.testSource>1.5</maven.compiler.testSource>
<maven.compiler.testTarget>1.5</maven.compiler.testTarget>
</properties>
Or by explicit configuration of the compiler plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
<testSource>1.5</testSource>
<testTarget>1.5</testTarget>
</configuration>
</plugin>

Maven generates duplicate pom.xml and pom.properties files in a jar

I package my Maven-based Spring app with:
mvn install-DskipTests -Peverything.
And something strange arises. In META-INF of generated jar, I find duplicate pom.xml and pom.properties files. Can someone explain it? Thanks.
Here is extracted pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.xyz</groupId>
<artifactId>migrate-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>migrate-app</name>
<url>http://maven.apache.org</url>
<dependencies>
..
</dependencies>
<profiles>
<profile>
<id>everything</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Output for command:
mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 15:44:56+0700)
Maven home: C:\apache-maven-3.0.4\bin..
Java version: 1.6.0_30, vendor: Sun Microsystems Inc.
Java home: C:\Program Files (x86)\Java\jdk1.6.0_30\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Add
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
</build>
to your pom.xml
It seems like this is a somewhat common problem that arises from a conflict in Eclipse, especially with the m2e-wtp integration.
Some people are indicating that it can be fixed by including clean in the list of goals to run, e.g. mvn clean package.
Also try to update your m2e installation and make sure you don't have multiple versions of m2e or m2eclipse (the pre-Indigo version) installed.
Some references to other people facing this problem:
http://dev.eclipse.org/mhonarc/lists/m2e-users/msg01995.html
https://issues.sonatype.org/browse/MECLIPSEWTP-209
https://issuetracker.springsource.com/browse/STS-2349
https://github.com/sonatype/m2eclipse-extras/issues/9
I know this issue is a bit old, but I thought I'd share an obscure bit of information on this subject. I was running across the same issue, and I found that when I ran maven with Eclipse open, AND my workspace preferences were set to refresh the workspace using native hooks or polling, the extra pom.xml and pom.properties files were added by eclipse! Closing eclipse or removing the refresh workspace option solved the problem for me. This was a hard one to track down, so hopefully someone else will benefit from this.
Follow up to #Dan's work around:
I tried your solution and it appears to work -- at first blush. However, it's just delaying the eventual failure.
It appears than anytime the workspace is refreshed the pom.xml and pom.properties files are created in the /classes directory. After that any later "package" goal will include the duplicate files in the .jar and thus break any later signing.
If the polling is on - you "fail-fast". If it's off you can fail at arbitrary times in future builds.
You need to do "mvn clean" and the do "mvn package" after that or just do "mvn clean package". if "mvn clean" fails due to any reason and if you do "mvn package" after that , you will see this issue again.
Not sure what you mean by duplicate but the jar created by maven does come with pom.xml and pom.properties in META-INF folder. See this section of the maven getting started guide.

"maven-resources-plugin prior to 2.4 is not supported by m2e"

I'm having problems with m2e (Maven plugin into Eclipse IDE).
I see the following error:
maven-resources-plugin prior to 2.4 is not supported by m2e. Use maven-resources-plugin version 2.4 or later.
I have no idea how to resolve this error. I'm pretty sure it is an m2e issue (maybe a setup thing?).
Background:
I'm attempting to build Tika v0.9
http://svn.apache.org/repos/asf/tika/tags/0.9/
I can build using Maven from command line.
I can build using Netbeans v7.0.1.
I am running Maven 3.0.3.
I am running Eclipse Indigo Service Release 1 (Build id: 20110916-0149)
I am running m2e v1.0.100.20110804-1717
Thanks for any help.
Albert
In the tika.parent project you can find org.apache.apache.6 as parent:
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>6</version>
<relativePath />
</parent>
And in the pom.xml from org.apache apache you can find:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
First simple solution:
add the following into the pom of tika.parent under "build - pluginManagement - plugins" (line 230):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
...
And then ask the tika team to use a newer org.apache apache parent pom.
How did you import your project into eclipse? (the mvn eclipse:eclipse goal, or "import maven project" in Eclipse?)
Maybe this answer is of relevance: Error in POM.xml
Another solution which worked for me is :
1) Uninstall all the existing Maven plugins from Ecplise.
2) Then install Maven plugin from this location : http://m2eclipse.sonatype.org/sites/m2e
-Rushi

Categories

Resources