0

I have this Maven project. I am trying to have Maven to automatically generate JavaDocs when mvn package is issued. The whole project compiles and packages just fine. It've generated documentation for all of my Java classes that are in the main package just fine but it did not generate documentation for any classes in sub packages. It said that it could not find them.

Exact error message is:

[WARNING] javadoc: warning - No source files for package parser

I've structured my project like this:

pom.xml
src (directory)
    main (directory)
        java (directory)
            parser (directory)
                Parser.java
                StringParser.java
                ByteParser.java
            Main.java
            Reader.java

The classes Main.java and Reader.java has 'package com.personal.reader;'. The classes in parser directory has 'package com.personal.reader.parser;'. It appears that the error message was saying that it cannot find 'com.personal.reader.parser'.

My pom.xml looks like this: (Deleted some stuff for brevity)

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.personal.reader</groupId>
    <artifactId>Reader</artifactId>
    <packaging>jar</packaging>
    <version>0.1.0</version>
    <name>Reader</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <outputDirectory>docs</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I've tried looking for solutions. Closest thing I've found is this StackOverflow question. There appears to be no clear answer. I've tried compiling the project that was linked in the submitter's answer to see if he had solved it or not. The submitter's project still exhibited same problems as I am having.

I have tried creating the package-info.java file in both src/main/java and src/main/java/parser. That seemed to not work.

I tried messing with maven-javadoc-plugins. I looked into sourceFileIncludes, includeDependencySources, subpackages, and dependencySourceIncludes. None of them seem to work. I might have missed something.

How do I fix this issue of Maven not including the subpackage to generate Javadocs?

Silence
  • 73
  • 3
  • 12

1 Answers1

2

It looks like I've found my answer. I'm posting it here so other people who is having the same problem can find it here.

How I did it: I had another go at the sourceFileIncludes tag in the maven-javadoc-plugins. I added this in the plugin in the project pom.xml.

<sourceFileIncludes>
    <sourceFileInclude>**/*.java</sourceFileInclude>
</sourceFileIncludes>

The whole plugin in the project pom.xml looks like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <outputDirectory>docs</outputDirectory>
        <sourceFileIncludes>
            <sourceFileInclude>**/*.java</sourceFileInclude>
        </sourceFileIncludes>
    </configuration>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

It've successfully generated Javadocs documents off on the classes in the parser directory. I suppose it would also work with other directories or deeper directories. If it doesn't, you can just add another <sourceFileInclude> under the <sourceFileIncludes> group with your own path.

I'm not one hundred percent sure if this is the correct answer but it sure does work fine for me. If someone else have a better solution, please go ahead and post it here.

Silence
  • 73
  • 3
  • 12