【问题标题】:How do I access maven project version in javadoc overview page?如何在 javadoc 概览页面中访问 maven 项目版本?
【发布时间】:2015-12-23 11:47:55
【问题描述】:

我正在使用PDFDocletmaven-javadoc-plugin,现在我已经取得了相当长的进展。我的 maven 和 javadoc 配置几乎已经足够好,但我现在的直接问题是我无法弄清楚如何将项目版本号推送到 PDF 标题页中。

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

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

Javadoc 通过读取src/main/javasrc/main/javadoc 中的文件来工作,AFAIK 将结果输出到target。这意味着过滤对于 Javadoc 没有用,因为它不会从 target 读取任何内容

我的结果表明 javadoc cmets 中的任何 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 pdf maven-javadoc-plugin


    【解决方案1】:

    我意识到我可以使用 maven &lt;resources&gt; 功能进行快速而肮脏的 hack:

      <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 列表中。

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      • 2017-02-08
      • 2021-04-30
      • 1970-01-01
      相关资源
      最近更新 更多