我使用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>
答案 0 :(得分:1)
asciidoctor-maven-plugin
不支持删除空目录。关于这一点有the issue 144,并且不考虑修复。
您可以在Ascii Doctor运行后使用Antrun Plugin和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
。