如何将Maven变量传递给asciidoctor-maven-plugin?

8

我有一个使用AsciiDoc编写的用户指南,尽管我没有花费太多时间,但它非常漂亮。

AsciiDoc插件很棒。因此,我想在用户指南中传递我的Maven最终名称。

问题: 如何做到这一点?

<finalName>${project.artifactId}-${project.version}-${version.state}-r${buildNumber}</finalName>

我使用的asciidoctor-maven-plugin配置如下:

<plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>${asciidoctor.maven.plugin.version}</version>
    <dependencies>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-pdf</artifactId>
            <version>${asciidoctorj.pdf.version}</version>
        </dependency>
        <!-- Comment this section to use the default jruby artifact provided by the plugin -->
        <dependency>
            <groupId>org.jruby</groupId>
            <artifactId>jruby-complete</artifactId>
            <version>${jruby.version}</version>
        </dependency>
        <!-- Comment this section to use the default AsciidoctorJ artifact provided by the plugin -->
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj</artifactId>
            <version>${asciidoctorj.version}</version>
        </dependency>
    </dependencies>
    <configuration>
        <sourceDirectory>src/docs/asciidoc</sourceDirectory>
        <sourceDocumentName>manual.adoc</sourceDocumentName>
        <!-- Attributes common to all output formats -->
        <attributes>
            <sourcedir>${project.build.sourceDirectory}</sourcedir>
        </attributes>
    </configuration>
    <executions>
        <execution>
            <id>generate-pdf-doc</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>process-asciidoc</goal>
            </goals>
            <configuration>
                <backend>pdf</backend>
                <!-- Since 1.5.0-alpha.9 PDF back-end can use 'rouge' as well as 'coderay'
            source highlighting -->
                <sourceHighlighter>rouge</sourceHighlighter>
                <attributes>
                    <icons>font</icons>
                    <pagenums/>
                    <toc/>
                    <idprefix/>
                    <idseparator>-</idseparator>
                </attributes>
            </configuration>
        </execution>
    </executions>
</plugin>
1个回答

11

官方用户指南 在其 传递 POM 属性 章节中介绍了这种情况:

可以将在 POM 中定义的属性传递给 Asciidoctor 处理器。例如,这对于在生成的文档中包括 POM 组件版本号非常方便。

这可以通过在 configurationattributes 部分中创建自定义的 AsciiDoc 属性来完成。AsciiDoc 属性值按照通常的 Maven 方式进行定义:${myMavenProperty}

<attributes>  
     <project-version>${project.version}</project-version>  
</attributes>

然后可以在文档中像这样使用自定义AsciiDoc属性:

The latest version of the project is {project-version}.
因此,您可以将以下内容应用于您现有的配置
<configuration>
    <sourceDirectory>src/docs/asciidoc</sourceDirectory>
    <sourceDocumentName>manual.adoc</sourceDocumentName>
    <!-- Attributes common to all output formats -->
    <attributes>
        <sourcedir>${project.build.sourceDirectory}</sourcedir>
        <!-- the new property -->
        <final-name>${project.build.finalName}</final-name>
    </attributes>
</configuration>

ASCII Doc 的用户指南非常好,现在我感到很惭愧,因为我之前没有找到它。感谢 @A. Di Matteo。 - Xelian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接