You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

spring-asciidoctor-backends使用问题:未生成Spring风格HTML文档

问题分析与解决方案

你遇到的核心问题是直接调用插件目标时未应用pom中<execution>块的配置,导致默认使用标准html后端而非spring-html。以下是具体解决步骤:

1. 执行正确的Maven命令

你当前执行的mvn asciidoctor:process-asciidoc是直接调用插件默认目标,不会加载<execution>内的自定义配置(包括指定的spring-html后端)。正确的执行方式有两种:

  • 触发绑定的Maven阶段:运行mvn prepare-package,该阶段会自动执行你配置的generate-html-documentation块,启用spring-html后端。
  • 或者将backend配置移到插件全局<configuration>块,这样直接调用mvn asciidoctor:process-asciidoc也会生效:
    <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <version>2.1.0</version>
        <!-- 全局配置,所有插件目标都会继承 -->
        <configuration>
            <backend>spring-html</backend>
        </configuration>
        <executions>
            <execution>
                <id>generate-html-documentation</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>process-asciidoc</goal>
                </goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>io.spring.asciidoctor.backends</groupId>
                <artifactId>spring-asciidoctor-backends</artifactId>
                <version>0.0.6</version>
            </dependency>
        </dependencies>
    </plugin>
    

2. 配置Asciidoc文档属性

在你的.adoc源文件开头添加Spring主题相关属性,确保样式正确加载:

:spring-theme: default
:spring-version: 5.3.20

如果不指定spring-theme,部分Spring特有的样式无法生效,会导致外观接近默认Asciidoc风格。

3. 检查静态资源生成

构建完成后,查看输出目录(默认是target/generated-docs)是否包含spring.css、spring.js等Spring后端静态资源。如果缺失,可在插件配置中添加资源复制规则:

<configuration>
    <backend>spring-html</backend>
    <resources>
        <resource>
            <directory>${project.basedir}/src/main/asciidoc</directory>
        </resource>
    </resources>
    <outputDirectory>${project.build.directory}/generated-docs</outputDirectory>
</configuration>

4. 验证版本兼容性

spring-asciidoctor-backends 0.0.6与asciidoctor-maven-plugin 2.1.0版本兼容,若问题仍存在,可尝试升级到两者的最新稳定版本。


内容的提问来源于stack exchange,提问作者Slevin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 12:35:04