4

My Maven Java 8 project is inside a path which contains accents: C:\Développements\myproject.

When I use maven-javadoc-plugin (event with last 2.10.4 version) I have this error when I try to generate the javadoc of my project (from IntelliJ IDEA 2016.2.4):

[ERROR] javadoc: warning - No source files for package com.mycompany.myproject
[ERROR] javadoc: error - No public or protected classes found to document.

This is strange because I have documented classes in this project.

Anthony O.
  • 22,041
  • 18
  • 107
  • 163

5 Answers5

6

This error can also occur if you have no public methods in your test classes, which is exactly what can happen because Sonar lint rule S5786 says JUnits should have default package visibility, for readability. Fortunately, you can use the -package javadoc option, to fix this. If you put this in your parent pom:

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <java.version>1.8</java.version>
  <maven.compiler.version>3.8.1</maven.compiler.version>
  <junit.version>5.7.0</junit.version>
 </properties>
...
<build>
  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>${maven.compiler.version}</version>
     <configuration>
      <source>${java.version}</source>
      <target>${java.version}</target>
     </configuration>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>3.0.0-M4</version>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-site-plugin</artifactId>
     <version>3.9.1</version>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-project-info-reports-plugin</artifactId>
     <version>3.1.1</version>
    </plugin>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-javadoc-plugin</artifactId>
     <version>3.2.0</version>
     <configuration>
      <source>8</source>
      <additionalOptions>-package</additionalOptions>
     </configuration>
    </plugin>
   </plugins>
  </pluginManagement>
 </build>
 <reporting>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
   </plugin>
  </plugins>
 </reporting>
 <distributionManagement>
  <site>
   <id>yourid</id>
   <url>file:///var/www/html/maven</url>
  </site>
 </distributionManagement>

then

mvn site-deploy

will give you your default maven site along with the javadoc. Included everything relevant for a Java 8 project.

karl
  • 1,059
  • 11
  • 12
3

Had this happen when I created a package-private class with a main method. After marking the class as public the packaging step worked again.

Ahatius
  • 4,777
  • 11
  • 49
  • 79
1

This is not a Maven or plugin problem but purely a Windows problem. Microsoft is too stupid to have a proper encoding set in cmd.exe. You have some stupid DOS encoding. Java's javadoc uses that to read the @options file and fails.

Set _JAVA_OPTIONS=-Dfile.encoding=UTF-8 and you are done. Alternatively, use a Linux distribution or FreeBSD.

The issue remains closed.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • 1
    Yes it's a Windows problem, but no, it's really a Maven bug because it's it who create the "options" file using UTF-8 encoding, and not the one of the platform used... – Anthony O. Oct 12 '16 at 08:46
  • No, it does not: https://github.com/apache/maven-plugins/blob/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java#L4331 If you think you can provide a good sample project and an idiotproof solution, I would be more than happy to reopen the issue and add it to the code. – Michael-O Oct 12 '16 at 08:58
0

Actually this is a referenced bug from maven-javadoc-plugin project: MJAVADOC-333.

So since it is not fixed (it is currently "closed"...) one should just remove the accents from your project path...

Anthony O.
  • 22,041
  • 18
  • 107
  • 163
0

Apart from the special character (accent) problem, this may be a problem with your pom.xml:

I had the same problems right now with a project created in Eclipse. If you create a project in eclipse, it will put java packages/sources directly within the src folder and add the following line to your pom.xml:

<sourceDirectory>src</sourceDirectory>.

If you then decide to move your java files according to the maven conventions and forget to update or remove the sourceDirectory tag, you will end up with exactly the same error:

Your project will build fine, but javadoc will not find it`s sources...

Stephan Richter
  • 1,139
  • 11
  • 31