Using maven properties in JavaDoc

前端 未结 2 1395
栀梦
栀梦 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 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

    
        
            
                src/main/resources
                true
            
        
    

    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}
    **/
    

提交回复
热议问题