简体   繁体   English

如何使用 maven 为包含包信息文件的项目生成测试 javadoc?

[英]How do I generate test javadoc for projects that contain package-info files with maven?

I'm trying to build the site for a Java project I'm working on.我正在尝试为我正在处理的 Java 项目构建站点。 The project contains several package-info.java files.该项目包含几个package-info.java文件。 The project itself is a Java 8 targeted project being built with Eclipse Adoptium JDK 11.0.15.10-hotspot.该项目本身是一个使用 Eclipse Adoptium JDK 11.0.15.10-hotspot 构建的 Java 8 目标项目。 To build the javadoc, I'm using the maven javadoc plugin.为了构建 javadoc,我使用了 maven javadoc 插件。 Maven builds the main javadoc fine. Maven 可以很好地构建主要的 javadoc。 However, when it builds the test javadoc, it complains about the package-info.class file containing the wrong class.但是,当它构建测试 javadoc 时,它会抱怨 package-info.class 文件包含错误的类。 For example:例如:

javadoc: error - An internal exception has occurred.
        (com.sun.tools.javac.code.ClassFinder$BadClassFile: bad class file: C:\workspaces\releases\9.99.0\foo-bar-baz\target\classes\com\mycompany\foo\bar\baz\package-info.class
  class file contains wrong class: com\mycompany\foo\bar\baz\package-info
  Please remove or make sure it appears in the correct subdirectory of the classpath.)

Naturally I assumed that I had some misspelling of the package name.自然地,我认为我的包名有一些拼写错误。 But that doesn't seem to be the case.但情况似乎并非如此。 The java file reads like this: java文件长这样:

/**
 * <p>
 * Some really cool javadoc about this package.
 * </p>
 */
package com.mycompany.foo.bar.baz;

This looks right.这看起来是对的。 So I'm a bit puzzled.所以我有点疑惑。 What is causing the javadoc executable to complain that the package-info contains the wrong class?是什么导致 javadoc 可执行文件抱怨 package-info 包含错误的类?

I was curious, so I looked at the class file using javap -v and got the following:我很好奇,所以我使用 javap -v 查看了类文件,得到了以下内容:

javap -v package-info.class
Classfile /C:/workspaces/releases/9.99.0/foo-bar-baz/target/classes/com/mycompany/foo/bar/baz/package-info.class
  Last modified Jun 5, 2022; size 142 bytes
  MD5 checksum xxxxxxxxxxxxxxxxxxxxxxxxxxx
  Compiled from "package-info.java"
interface com\mycompany\foo\bar\baz\package-info
  minor version: 0
  major version: 52
  flags: (0x1600) ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC
  this_class: #3                          // "com\\mycompany\\foo\\bar\\baz\\package-info"
  super_class: #5                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 0, attributes: 1
Constant pool:
  #1 = Utf8               package-info.java
  #2 = Utf8               com\\mycompany\\foo\\bar\\baz\\package-info
  #3 = Class              #2              // "com\\mycompany\\foo\\bar\\baz\\package-info"
  #4 = Utf8               java/lang/Object
  #5 = Class              #4              // java/lang/Object
  #6 = Utf8               SourceFile
{
}
SourceFile: "package-info.java"

It turns out the process of generating these package-info classes used incorrect slashes.事实证明,生成这些包信息类的过程使用了不正确的斜杠。 After doing some digging, it looks like this was the result of a defect in maven-compiler-plugin 3.10.0 ( https://issues.apache.org/jira/browse/MCOMPILER-485 ).在进行了一些挖掘之后,看起来这是 maven-compiler-plugin 3.10.0 ( https://issues.apache.org/jira/browse/MCOMPILER-485 ) 中存在缺陷的结果。 Updating to 3.10.1 fixed this issue.更新到 3.10.1 解决了这个问题。 Alternatively, compiling in Linux using version 3.10.0 works as well.或者,使用 3.10.0 版本在 Linux 中编译也可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM