7

I'm writing a maven package with directory structure

frtex
   pom.xml
frtex/src/main/java/some-files.java
frtex/src/main/java/utils/some-other-files.java

Making mvn test works fine.

My problem is mvn javadoc:javadoc that produces the right documentation for the files contained in frtex/src/main/java but issuing

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

Here is the relevant(?) part of my pom.xml :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.10.4</version>
    <configuration>
        <groups>
            <group>
                <title>TI</title>
                <packages>frtex.*</packages>
            </group>
        </groups>

        <doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
        <docletArtifact>
            <groupId>ch.raffael.pegdown-doclet</groupId>
            <artifactId>pegdown-doclet</artifactId>
            <version>1.1</version>
        </docletArtifact>
        <useStandardDocletOptions>true</useStandardDocletOptions>
    </configuration>
</plugin>

in project/build/plugins

What should I do to make maven/javadoc found the files in src/main/java/utils ?

4 Answers 4

11

This is a late response, but I just ran into the same issue.

The solution is you need to add the following to your plugin inside the configuration section

<configuration>
   <sourcepath>src/main/java</sourcepath>
   ...
</configuration>
6
  • 6
    Would be interesting to know why this should work, because it's the default path.
    – PowerStat
    Jun 18, 2019 at 18:59
  • 3
    strangely, this does help. I'm inheriting this from parent pom so maybe the default is not set in some cases
    – jediz
    Mar 26, 2020 at 13:33
  • This is helpful, but I think it solves a newer problem than the OP’s. The maven-javadoc-plugin uses a different default sourcepath, ${project.build.directory}/apidocs/src during the deploy phase, unless you configure it in your pom.xml as ${project.build.sourceDirectory}. Apr 28, 2020 at 3:08
  • 1
    Not the OPs problem but it solved mine, and I found OP's post using the error message, so it's useful info! Jun 10, 2020 at 5:12
  • I tried this, but I still get this problem... Sep 20, 2021 at 0:30
5

The problem is not in your maven configuration.

You need to include a package-info.java for the utils package.

It is a file located at src/main/java/utils/package-info.java that will contain the javadoc for the package, in contrast to the javadoc for a class.

For more information about package-level javadocs, you can read the documentation.

5
  • How do I invoke maven after that ? Just adding the proposed file and invoking mvn javadoc:javadoc results in the same warning. Jun 22, 2016 at 4:23
  • I don't know your entire setup, but generally you need to run your maven build to get a new build. It might be possible to run a specific target (like you did) to get the desired item, but knowing the exact way to run that specific target is unique to each maven build configuration. If it were me, I'd just run a new full build.
    – Edwin Buck
    Jun 22, 2016 at 14:48
  • Why getting javadoc: warning - No source files for package utils , is it because missing package-info.java ?
    – prime
    Aug 12, 2017 at 1:33
  • @prime Probably.
    – Edwin Buck
    Aug 14, 2017 at 0:46
  • Something I noticed was that the package-info.java file is not compiled unless you specify annotation with Retention=RUNTIME or pass -Xpkginfo:always to javac. The package-info.java kind of solves this problem but introduces one of the aforementioned workarounds. I am not convinced that this is a better option than the sourcepath configuration, but it's definitely a good alternative. Aug 31, 2020 at 18:42
5

Although locus2k's answer worked for me in the beginning, it was only covering up the real underlying issue I had with Javadoc not being able to find the directory structure.

In my case, I created in IntelliJ -by mistake- a single dir structure with dots separating them, like: src/main/java/wrong.folder.structure/ instead of: src/main/java/right/folder/structure/

The collapsed view in IntelliJ was showing both structures as the same.

Maybe not everyone's issue, but it was mine.

1
1

This problem can also occur, if you use a newer Java version to build the project, though the warning is an error then, which makes the build fail. In my case, I was building a Java 8 project with a Java 12 (Bellsoft) JDK.

To solve this, you could either use a Java 8 JDK or, perhaps better, add <source>8</source> to the configuration section of the maven-javadoc-plugin (similar to @locus2k solution).

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.