如何将 Maven 变量传递给 asciidoctor-maven-plugin?
How to pass Maven variable to asciidoctor-maven-plugin?
我有使用 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>
official user guide cover this case in its Passing POM properties 部分:
It is possible to pass properties defined in the POM to the Asciidoctor processor. This is handy for example to include in the generated document the POM artifact version number.
This is done by creating a custom AsciiDoc property in the attributes
section of the configuration
. The AsciiDoc property value is defined in the usual Maven way: ${myMavenProperty}
.
<attributes>
<project-version>${project.version}</project-version>
</attributes>
The custom AsciiDoc property can then be used in the document like this:
The latest version of the project is {project-version}.
因此,您可以将以下内容应用于现有的 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>
我有使用 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>
official user guide cover this case in its Passing POM properties 部分:
It is possible to pass properties defined in the POM to the Asciidoctor processor. This is handy for example to include in the generated document the POM artifact version number.
This is done by creating a custom AsciiDoc property in the
attributes
section of theconfiguration
. The AsciiDoc property value is defined in the usual Maven way:${myMavenProperty}
.<attributes> <project-version>${project.version}</project-version> </attributes>
The custom AsciiDoc property can then be used in the document like this:
The latest version of the project is {project-version}.
因此,您可以将以下内容应用于现有的 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>