在 JavaDoc 中使用 Maven 属性
Using maven properties in JavaDoc
是否可以使用 Maven Javadoc 插件在 javadoc 上扩展 Maven 属性的范围?例如
/**
* My Awesome Class
* @version ${project.version}
**/
show
String
Specifies the access level for classes and members to
show in the Javadocs. Possible values are: public (shows only public
classes and members) protected (shows only public and protected
classes and members) package (shows all classes and members not marked
private) private (shows all classes and members)
Default value is: protected. User property is: show.
https://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html
尝试将节目放public
我想你可以这样试试。这是两步过程:
首先是将 pom 属性 加载到静态字段中
其次使用静态字段设置javadoc 属性
在 src/main/resources
中创建一个 app.properties
内容如下
application.version=${project.version}
然后像这样启用 Maven 过滤
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
在应用程序代码中只读取属性文件
public class MVNLinksHolder{
public static String version = "";
public MVNLinksHolder(){
ClassPathResource resource = new ClassPathResource( "app.properties" );
Properties p = new Properties();
InputStream inputStream = null;
try {
inputStream = resource.getInputStream();
p.load( inputStream );
version = p.getProperty("application.version");
}
catch ( IOException e ) {
LOGGER.error( e.getMessage(), e );
}
finally {
Closeables.closeQuietly( inputStream );
}
}
}
然后用它来设置版本
/**
* My Awesome Class
* @version = {@value MVNLinksHolder#version}
**/
是否可以使用 Maven Javadoc 插件在 javadoc 上扩展 Maven 属性的范围?例如
/**
* My Awesome Class
* @version ${project.version}
**/
show
String
Specifies the access level for classes and members to show in the Javadocs. Possible values are: public (shows only public classes and members) protected (shows only public and protected classes and members) package (shows all classes and members not marked private) private (shows all classes and members)Default value is: protected. User property is: show.
https://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html
尝试将节目放public
我想你可以这样试试。这是两步过程: 首先是将 pom 属性 加载到静态字段中 其次使用静态字段设置javadoc 属性
在 src/main/resources
中创建一个 app.properties
内容如下
application.version=${project.version}
然后像这样启用 Maven 过滤
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
在应用程序代码中只读取属性文件
public class MVNLinksHolder{
public static String version = "";
public MVNLinksHolder(){
ClassPathResource resource = new ClassPathResource( "app.properties" );
Properties p = new Properties();
InputStream inputStream = null;
try {
inputStream = resource.getInputStream();
p.load( inputStream );
version = p.getProperty("application.version");
}
catch ( IOException e ) {
LOGGER.error( e.getMessage(), e );
}
finally {
Closeables.closeQuietly( inputStream );
}
}
}
然后用它来设置版本
/**
* My Awesome Class
* @version = {@value MVNLinksHolder#version}
**/