Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maven properties in JavaDoc

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

/**
 * My Awesome Class
 * @version ${project.version}
**/
like image 215
ovnia Avatar asked Jul 24 '15 06:07

ovnia


1 Answers

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}
**/
like image 177
Garry Avatar answered Sep 18 '22 21:09

Garry