如何在javadoc概述页面中访问maven项目版本



我将PDFDocletmaven-javadoc-plugin结合使用,现在我已经在这方面取得了长足的进步。我的maven和javadoc配置几乎已经足够好了,但我现在的直接问题是,我不知道如何将项目版本号推送到PDF标题页中。

在你告诉我使用maven的<resource>过滤来回答我的问题之前,让我概述一下为什么这不起作用。

过滤的工作原理是从src文件夹中的某个位置获取原始文件,进行变量替换并将输出放入target文件夹。

Javadoc的工作原理是读取src/main/javasrc/main/javadoc中的文件,并将结果输出到target中。这意味着过滤对Javadoc来说是无用的,因为它不会从target 中读取任何内容

我的结果表明,javadoc注释中的任何maven变量都不会被替换。

我可以使用什么技巧将这些变量替换到javadoc中?

该解决方案不能在site:site任务之后过滤javadoc输出,除非资源过滤对PDF有效。

这是配置,FWIW:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.10.3</version>
    <configuration>
      <show>package</show>
      <docfilessubdirs>true</docfilessubdirs>
      <tags>
        <tag>
          <name>pdfInclude</name>
          <placement>X</placement>
          <head></head>
        </tag>
      </tags>
    </configuration>
    <reportSets>
      <reportSet>
        <id>PDF</id>
        <reports>
          <report>javadoc</report>
        </reports>
        <configuration>
          <name>PDF</name>
          <description>PDF doc</description>
          <destDir>pdf</destDir>
          <doclet>com.tarsec.javadoc.pdfdoclet.PDFDoclet</doclet>
          <docletPath>${basedir}/pdfdoclet/pdfdoclet-1.0.3-all.jar</docletPath>
          <useStandardDocletOptions>false</useStandardDocletOptions>
          <additionalparam>-pdf my_tech_doc-${project.version}.pdf
            -config ${basedir}/pdfdoclet/pdfdoclet.properties</additionalparam>
        </configuration>
      </reportSet>
    </reportSets>
  </plugin>

pdfdoclet.properties:

    # http://pdfdoclet.sourceforge.net/configuration.html
    #
    #Lets the doclet print additional output in the console and to a logfile.
    debug=true 
    #Print "Author" tags
    author=false  
    #Print "Version" tags
    version=true
    #Print "since" tags
    tag.since=true
    #Create summary tables
    summary.table=false
    #Create hyperlinks
    create.links=true
    #Encrypt the PDF file
    encrypted=false
    #Allow printing of the PDF file
    allow.printing=true 
    #Create a bookmark frame
    create.frame=true
    #Print a title page
    api.title.page=true
    api.copyright=None
    api.author=Hansruedi
    #Enables the tag-based filter
    filter=true
    filter.tags=pdfInclude
    font.text.name=resources/arial.ttf
    page.orientation=portrait

PDFDoclet特定的api.*属性应该会产生一个标题页作为PDF的第一页,但它不起作用。如果我在这里错过了一个技巧,我可以制作出标题页,那么这可能也会以某种方式提供解决方案。

我意识到我可以用maven <resources>功能进行快速而肮脏的破解:

  <resource>
    <directory>${basedir}/src/main/resources</directory>
    <targetPath>${basedir}/src/main/javadoc</targetPath>
    <filtering>true</filtering>
    <includes>
      <include>**/overview.html</include>
    </includes>
  </resource>

这将复制我的overview.html并对其进行筛选,将其输出到javadoc源目录中。

肮脏的是,这个过滤后的版本可能会意外地被版本控制,尽管使用svn我可以将其添加到ignore列表中。

最新更新