Using maven properties in JavaDoc

前端 未结 2 1396
栀梦
栀梦 2021-02-08 11:42

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

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


        
相关标签:
2条回答
  • 2021-02-08 11:55

    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

    0 讨论(0)
  • 2021-02-08 12:04

    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}
    **/
    
    0 讨论(0)
提交回复
热议问题