Using maven properties in JavaDoc

可紊 提交于 2019-12-09 05:23:05

问题


Is it possible to expand the maven properties' scope on javadocs using Maven Javadoc Plugin? E.g.

/**
 * My Awesome Class
 * @version ${project.version}
**/

回答1:


I think you try like this. This is two step process: First is to load the pom property into static field Second to use the static field to set the javadoc property

Create a app.properties in src/main/resources with content like this

application.version=${project.version}

then enable maven filtering like this

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

In application code just read properties file

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 );
    }
}
}

Then use it to set the version

/**
 * My Awesome Class
 * @version = {@value MVNLinksHolder#version}
**/



回答2:


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

Try putting show to public



来源:https://stackoverflow.com/questions/31604144/using-maven-properties-in-javadoc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!