[英]swagger-maven-plugin triggers Javadoc warning: element value must be a constant expression (but it is!) in Java annotation
Javadoc (via Maven) is giving me the following error in one my Java JAX-RS interface method signatures: Javadoc(通过Maven)在我的Java JAX-RS接口方法签名中给出了以下错误:
error: element value must be a constant expression
Here is my JAX-RS interface: 这是我的JAX-RS接口:
public interface FooResource {
@Consumes(APPLICATION_FORM_URLENCODED_UTF_8)
public void bar();
}
Javdoc gives the error for @Consumes
. Javdoc给出了错误
@Consumes
。 Here is the definition for APPLICATION_FORM_URLENCODED_UTF_8
, which appears in MyAppConstants
in the same project: 以下是
APPLICATION_FORM_URLENCODED_UTF_8
的定义,它出现在同一项目的MyAppConstants
中:
public static final String APPLICATION_FORM_URLENCODED_UTF_8 =
APPLICATION_FORM_URLENCODED + ";" + CHARSET_PARAMETER + "=UTF-8";
And here is the definition of APPLICATION_FORM_URLENCODED
, which appears in javax.ws.rs.core.MediaType
: 以下是
APPLICATION_FORM_URLENCODED
的定义,它出现在javax.ws.rs.core.MediaType
:
public final static String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
And here is the definition of CHARSET_PARAMETER
, which also appears in javax.ws.rs.core.MediaType
: 这里是
CHARSET_PARAMETER
的定义,它也出现在javax.ws.rs.core.MediaType
:
public static final String CHARSET_PARAMETER = "charset";
Now I ask you: what about APPLICATION_FORM_URLENCODED_UTF_8
is not constant at compile time? 现在我问你:在编译时,
APPLICATION_FORM_URLENCODED_UTF_8
不是常量吗?
The error message didn't say that I have to provide a literal . 错误消息没有说我必须提供文字 。 It said I had to provide a constant .
它说我必须提供一个常数 。 So what about this is not a constant?
那么这不是一个常数呢?
(I could almost swear that this worked at one time but suddenly stopped working.) (我几乎可以发誓这种情况曾经有效但突然停止了工作。)
Update: Found cause, but still don't understand. 更新: 找到原因,但仍然不明白。
For some reason, merely including the swagger-maven-plugin
in the POM will trigger this problem! 出于某种原因,仅仅在POM中包含
swagger-maven-plugin
就会触发这个问题! My code doesn't change at all, but as soon as I add the following dependency, suddenly I get Javadoc warnings for my existing code!!! 我的代码根本没有改变,但是一旦我添加了以下依赖项,突然我得到了现有代码的Javadoc警告!
<dependency>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.5</version>
</dependency>
How can a single dependency make Javadoc work differently on a code file? 单个依赖如何使Javadoc在代码文件上的工作方式不同? What is
swagger-maven-plugin
doing? 什么是
swagger-maven-plugin
呢?
My best guess is that this happens because swagger-maven-plugin
transitively (via io.swagger:swagger-core:1.5.13
) an old version of the JAX-RS specification in javax.ws.rs:jsr311-api:1.1.1
. 我最好的猜测是,这是因为
swagger-maven-plugin
传递(通过io.swagger:swagger-core:1.5.13
) javax.ws.rs:jsr311-api:1.1.1
旧版本的JAX-RS规范javax.ws.rs:jsr311-api:1.1.1
。 Note that the JAX-RS 2 artifact ID is javax.ws.rs-api
, Maven doesn't realize that they are different versions of the same JAR, and pulls them both in as dependencies. 请注意,JAX-RS 2工件ID是
javax.ws.rs-api
,Maven没有意识到它们是同一JAR的不同版本,并将它们作为依赖项拉入。 I can only guess that javax.ws.rs:jsr311-api
in fact does not use constants for the variables in question. 我只能猜测
javax.ws.rs:jsr311-api
实际上并没有对有问题的变量使用常量。 In any case, when I threw out swagger-maven-plugin
and pulled in io.swagger:swagger-annotations
(which was all I needed in this project for documentation), the problem went away. 无论如何,当我抛出
swagger-maven-plugin
并拉入io.swagger:swagger-annotations
(这是我在这个项目中需要的所有文档)时,问题就消失了。
See https://github.com/kongchen/swagger-maven-plugin/issues/543 . 请参阅https://github.com/kongchen/swagger-maven-plugin/issues/543 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.