Spring 源码调试问题 ( List.of(“bin“, “build“, “out“); )

Spring 源码调试问题

一、问题描述

错误:springframework\buildSrc\src\main\java\org\springframework\build\CheckstyleConventions.java:68: 错误: 找不到符号
List<String> buildFolders = List.of("bin", "build", "out");
^
符号:方法 of(java.lang.String,java.lang.String,java.lang.String)

位置:接口 java.util.List

源码错误文件如下

/*
 * Copyright 2002-2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.build;

import java.io.File;
import java.nio.file.Path;
import java.util.List;

import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
import io.spring.nohttp.gradle.NoHttpExtension;
import io.spring.nohttp.gradle.NoHttpPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.quality.Checkstyle;
import org.gradle.api.plugins.quality.CheckstyleExtension;
import org.gradle.api.plugins.quality.CheckstylePlugin;

/**
 * {@link Plugin} that applies conventions for checkstyle.
 *
 * @author Brian Clozel
 */
public class CheckstyleConventions {

	/**
	 * Applies the Spring Java Format and Checkstyle plugins with the project conventions.
	 * @param project the current project
	 */
	public void apply(Project project) {
		project.getPlugins().withType(JavaBasePlugin.class, (java) -> {
			if (project.getRootProject() == project) {
				configureNoHttpPlugin(project);
			}
			project.getPlugins().apply(CheckstylePlugin.class);
			project.getTasks().withType(Checkstyle.class).forEach(checkstyle -> checkstyle.getMaxHeapSize().set("1g"));
			CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class);
			checkstyle.setToolVersion("10.14.2");
			checkstyle.getConfigDirectory().set(project.getRootProject().file("src/checkstyle"));
			String version = SpringJavaFormatPlugin.class.getPackage().getImplementationVersion();
			DependencySet checkstyleDependencies = project.getConfigurations().getByName("checkstyle").getDependencies();
			checkstyleDependencies.add(
					project.getDependencies().create("io.spring.javaformat:spring-javaformat-checkstyle:" + version));
		});
	}

	private static void configureNoHttpPlugin(Project project) {
		project.getPlugins().apply(NoHttpPlugin.class);
		NoHttpExtension noHttp = project.getExtensions().getByType(NoHttpExtension.class);
		noHttp.setAllowlistFile(project.file("src/nohttp/allowlist.lines"));
		noHttp.getSource().exclude("**/test-output/**", "**/.settings/**",
				"**/.classpath", "**/.project", "**/.gradle/**");
		List<String> buildFolders = List.of("bin", "build", "out"); // 错误位置
		project.allprojects(subproject -> {
			Path rootPath = project.getRootDir().toPath();
			Path projectPath = rootPath.relativize(subproject.getProjectDir().toPath());
			for (String buildFolder : buildFolders) {
				Path innerBuildDir = projectPath.resolve(buildFolder);
				noHttp.getSource().exclude(innerBuildDir + File.separator + "**");
			}
		});
	}

}

二、解决方案

Gradle JVM 版本过低,需要在 Java 8 版本以上,建议 Java 17,因为官方 Spring 版本用的就是 Java 17

Settings 里面的 gradle JVM 配置设置为 Java 17 即可

在这里插入图片描述

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-02 07:00:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-02 07:00:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-02 07:00:06       87 阅读
  4. Python语言-面向对象

    2024-04-02 07:00:06       96 阅读

热门阅读

  1. C#WPF设置圆角按钮样式

    2024-04-02 07:00:06       33 阅读
  2. ElasticSearch的DSL查询

    2024-04-02 07:00:06       41 阅读
  3. linxu tensorflow-1.13.1 C++动态库编译

    2024-04-02 07:00:06       34 阅读
  4. 介绍 TensorFlow 的基本概念和使用场景

    2024-04-02 07:00:06       31 阅读
  5. 【OpenCV-环境搭建】

    2024-04-02 07:00:06       39 阅读
  6. 【C/C++】C语言实现顺序表

    2024-04-02 07:00:06       33 阅读
  7. 手搓ajax的封装

    2024-04-02 07:00:06       39 阅读
  8. npm常用命令详解

    2024-04-02 07:00:06       39 阅读
  9. js怎样获取到时间戳?

    2024-04-02 07:00:06       36 阅读
  10. 给手机换电池、贴膜:VIVO服务还是非常好的

    2024-04-02 07:00:06       159 阅读