简体   繁体   English

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

[英]How to pass Maven variable to asciidoctor-maven-plugin?

I have user-guide which uses AsciiDoc it is very beautiful despite that I did not spend much time for it. 我有使用AsciiDoc的用户指南它很漂亮,尽管我没有花太多时间。

AsciiDoc plugins are awesome. AsciiDoc插件很棒。 So I want to pass my Maven final name in the user guide. 所以我想在用户指南中传递我的Maven最终名称。

Question : How to do that? 问题 :怎么做?

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

My asciidoctor-maven-plugin configurations are: 我的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>

The official user guide cover this case in its Passing POM properties section: 官方用户指南Passing POM属性部分介绍了这种情况:

It is possible to pass properties defined in the POM to the Asciidoctor processor. 可以将POM中定义的属性传递给Asciidoctor处理器。 This is handy for example to include in the generated document the POM artifact version number. 例如,在生成的文档中包含POM工件版本号是很方便的。

This is done by creating a custom AsciiDoc property in the attributes section of the configuration . 这是通过在configurationattributes部分中创建自定义AsciiDoc属性来完成的。 The AsciiDoc property value is defined in the usual Maven way: ${myMavenProperty} . AsciiDoc属性值以通常的Maven方式定义: ${myMavenProperty}

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

The custom AsciiDoc property can then be used in the document like this: 然后可以在文档中使用自定义的AsciiDoc属性,如下所示:

 The latest version of the project is {project-version}. 

Accordingly, you can hence apply the following to your existing configuration : 因此,您可以将以下内容应用于现有configuration

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM