2

Not sure why Maven Javadoc Plugin reports:

[ERROR] /project/src/main/a/b/SomeClass.java:3: error: package com.x does not exist
[ERROR] import com.x.y;

The plugin related part in pom.xml

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <sourcepath>${project.basedir}/src/main/java</sourcepath>
                    <excludePackageNames>com.x.*</excludePackageNames>
                    <dependencySourceExcludes>com.x.*</dependencySourceExcludes>
                </configuration>
            </plugin>

As can be seen from the above code I tried to include the project sources that I want to be processed by JavaDoc in <sourcepath> and exclude the problematic package

The problem may be caused by the fact that package com.x.y is contained within an external jar which is added to the project in the following configuration:

           <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <configuration>
                            <tasks>
                                <echo>Unpack JAR archive with JNI interface</echo>
                                <unjar src="${project.basedir}/x/lib63.jar" dest="${project.build.directory}/classes">
                                    <patternset>
                                        <include name="**/*.class"/>
                                    </patternset>
                                </unjar>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

How to ignore those import errors?

I don't use the plugin on daily basis so I may not understand all the nuances. But I don't understand why it even tries to analyze the imports. Shouldn't it just analyze my sources and create html files based on javadoc comments?

P.S. Without javadoc plugin the build is successful

ka3ak
  • 2,435
  • 2
  • 30
  • 57
  • 2
    Why is the package add via antrun plugin? Install it into a repository manager and second I really strongly recommend to upgrade your plugins... – khmarbaise Oct 29 '21 at 14:36
  • 1
    Why the f...hell are these external classes added like this? Is this a case of "when long-time Ant users become Maven users"? :) This is even weirder than the usual simple, but likewise wrong approach to copy a dependency's JAR into a `lib` folder. The clean Maven way is to [`install:install-file`](https://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html) into a local repo or to [`deploy:deploy-file`](https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html) into a remote repo and declare the JAR as `` in the POM. – Gerold Broser Oct 29 '21 at 14:47
  • 1
    As was said before. A proper `` will probably solve your problems. – J Fabian Meier Oct 29 '21 at 14:52
  • 1
    @GeroldBroser The external jar may come from another company – ka3ak Oct 29 '21 at 15:35
  • 1
    @ka3ak This does not make a difference. You need to use a proper ``, not some Ant unjar task. – J Fabian Meier Oct 29 '21 at 15:48
  • It doesn't matter were it comes from. A JAR is JAR and there is a canonical way to handle such external ones in Maven. I described it above. – Gerold Broser Oct 29 '21 at 15:48
  • @GeroldBroser Yeah, I know. Thanks. I've installed it manually and it works, but it would be great to know how to accomplish it with some configuration in pom.xml, so that it's installed into local repo during build (or before the build). – ka3ak Oct 29 '21 at 15:49
  • @GeroldBroser I think I've found the answer here https://stackoverflow.com/a/38339518/971355 Trying... – ka3ak Oct 29 '21 at 15:52
  • Yes, that's it. Just in case, the manual ways: https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html, https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html. – Gerold Broser Oct 29 '21 at 15:54

0 Answers0