gpt4 book ai didi

maven - 如何使用 Asciidoctor maven 插件排除空文件夹

转载 作者:行者123 更新时间:2023-12-04 03:17:21 27 4
gpt4 key购买 nike

我使用 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不支持删除空目录。有 the issue 144关于这一点,并且不考虑修复它。

您可以使用 Antrun Plugin 解决这个问题和 delete empty directories在 Ascii Doctor 运行之后:

<!-- 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 之后,并确保它们绑定(bind)到同一阶段。我在上面的示例中使用了 generate-resources

关于maven - 如何使用 Asciidoctor maven 插件排除空文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40059943/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com