# Java 编译文档提示 text blocks are not supported in -source 11 错误

**URL:** <https://www.isharkfly.com/t/java-text-blocks-are-not-supported-in-source-11/15693>\
**Category:** 程序语言\
**Tags:** java, maven\
**Created:** [April 30, 2024, 9:19pm UTC](https://www.isharkfly.com/t/java-text-blocks-are-not-supported-in-source-11/15693 "2024-04-30T21:19:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [April 30, 2024, 9:19pm UTC](https://www.isharkfly.com/t/java-text-blocks-are-not-supported-in-source-11/15693/1 "2024-04-30T21:19:51Z")

</div>

错误的日志信息为：

```auto
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.6.3:jar (attach-javadocs) on project core-java-strings: MavenReportException: Error while generating Javadoc: 
[ERROR] Exit code: 1
[ERROR] C:\WorkDir\Repository\iSharkfly-Docs\java-tutorials\core-java-modules\core-java-strings\src\main\java\com\baeldung\multiline\MultiLineString.java:68: error: text blocks are not supported in -source 11
[ERROR] return """
[ERROR] ^
[ERROR] (use -source 15 or higher to enable text blocks)
[ERROR] 1 error
[ERROR] Command line was: cmd.exe /X /C "C:\Progra~1\Semeru\jdk-17.0.6.10-openj9\bin\javadoc.exe @options @packages"
[ERROR]
[ERROR] Refer to the generated Javadoc files in 'C:\WorkDir\Repository\iSharkfly-Docs\java-tutorials\core-java-modules\core-java-strings\target\apidocs' dir.
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :core-java-strings

```

 ![2024-04-30_17-16-09](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/b/bdfd4d6a71e2e37f314370005a65100c71826d10.png)

## 问题和原因

出现上面错误信息的原因是在Java 代码编译的时候我们使用了一些在 JDK-17 中才有的属性。

但是生成的 Doc 文档却是使用的是 JDK 11。

我们需要做的就是在 maven-javadoc-plugin 插件中指定 JDK 的版本。

对插件添加下面的内容：

```xml
                <configuration>
                    <release>${java.version}</release>
                    <encoding>UTF-8</encoding>
                </configuration>

```

因为我们上面使用了全局配置变量，所以这里用的是变量类型，你也可以在这里直接使用数字 17。

配置参数：

```xml
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>${maven-javadoc-plugin.version}</version>
                <configuration>
                    <release>${java.version}</release>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

```

 ![2024-04-30_17-19-25](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/e/e13737c294861dd45f950a12b978f4c34d1d4a2a.png)

把上图中的配置参数添加到 POM 文件中。
