ovnia
ovnia

Reputation: 2500

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

Upvotes: 10

Views: 733

Answers (2)

Garry
Garry

Reputation: 4533

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

Upvotes: 2

arodriguezdonaire
arodriguezdonaire

Reputation: 5562

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

Upvotes: 0

Related Questions