如何使用 Asciidoctor maven 插件排除空文件夹
How can I exclude empty folders with Asciidoctor maven plugin
我使用 Asciidoctor Maven 插件从 adoc 生成 HTML。不幸的是,它从 sourceDirectory
中指定的目录复制每个源目录。如何排除这些空文件夹?
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>test-id</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>mysourcedirectory</sourceDirectory>
<sourceDocumentName>Test.adoc</sourceDocumentName>
<outputDirectory>${project.build.directory}/outputdir</outputDirectory>
<relativeBaseDir>true</relativeBaseDir>
<preserveDirectories>true</preserveDirectories>
<backend>html</backend>
</configuration>
</execution>
</executions>
</plugin>
我的输入目录是这样的:
── mysourcedirectory
├── Test.adoc
└── subfolder1
├── doc1.adoc
└── doc2.adoc
asciidoc 的输出如下所示(subfolder1
为空,我希望将其排除):
── mysourcedirectory
├── Test.adoc
└── subfolder1
根据 Asciidoc (https://github.com/asciidoctor/asciidoctor-maven-plugin#configuration-options) 的文档,我可以使用 resources
标签来完成。我已经尝试过这种方法,但它不起作用:
<configuration>
<resources>
<resource>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
...
</configuration>
那个asciidoctor-maven-plugin
does not support the removal of empty directories. There is the issue 144,暂时不考虑修复
您可以在 Ascii Doctor 有 运行:
之后使用 Antrun Plugin and delete empty directories 来解决这个问题
<!-- your configuration of Ascii Doctor -->
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<!-- rest of your config -->
</plugin>
<!-- deleting empty directories in output directory of Ascii Doctor -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>delete-empty-dirs</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete includeemptydirs="true">
<fileset dir="${project.build.directory}/generated-docs">
<and>
<size value="0" />
<type type="dir" />
</and>
</fileset>
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>
为了确保在 Ascii Doctor 之后调用 Antrun 插件,您可以将其声明放在 asciidoctor-maven-plugin
之后,并确保它们绑定到同一阶段。我在上面的例子中使用了generate-resources
。
我使用 Asciidoctor Maven 插件从 adoc 生成 HTML。不幸的是,它从 sourceDirectory
中指定的目录复制每个源目录。如何排除这些空文件夹?
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>test-id</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>mysourcedirectory</sourceDirectory>
<sourceDocumentName>Test.adoc</sourceDocumentName>
<outputDirectory>${project.build.directory}/outputdir</outputDirectory>
<relativeBaseDir>true</relativeBaseDir>
<preserveDirectories>true</preserveDirectories>
<backend>html</backend>
</configuration>
</execution>
</executions>
</plugin>
我的输入目录是这样的:
── mysourcedirectory
├── Test.adoc
└── subfolder1
├── doc1.adoc
└── doc2.adoc
asciidoc 的输出如下所示(subfolder1
为空,我希望将其排除):
── mysourcedirectory
├── Test.adoc
└── subfolder1
根据 Asciidoc (https://github.com/asciidoctor/asciidoctor-maven-plugin#configuration-options) 的文档,我可以使用 resources
标签来完成。我已经尝试过这种方法,但它不起作用:
<configuration>
<resources>
<resource>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
...
</configuration>
那个asciidoctor-maven-plugin
does not support the removal of empty directories. There is the issue 144,暂时不考虑修复
您可以在 Ascii Doctor 有 运行:
之后使用 Antrun Plugin and delete empty directories 来解决这个问题<!-- your configuration of Ascii Doctor -->
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<!-- rest of your config -->
</plugin>
<!-- deleting empty directories in output directory of Ascii Doctor -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>delete-empty-dirs</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete includeemptydirs="true">
<fileset dir="${project.build.directory}/generated-docs">
<and>
<size value="0" />
<type type="dir" />
</and>
</fileset>
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>
为了确保在 Ascii Doctor 之后调用 Antrun 插件,您可以将其声明放在 asciidoctor-maven-plugin
之后,并确保它们绑定到同一阶段。我在上面的例子中使用了generate-resources
。