alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.47k stars 8.19k forks source link

[Spring Boot 3.0 Adaptive] Checkstyle plugin #2961

Closed ruansheng8 closed 11 months ago

ruansheng8 commented 1 year ago

背景说明

升级SpringBoot 3.0 相关依赖以后 , checkstyle plugin 版本未改动的情况下 , 原有未改动过的代码checkstyle检查也无法通过 , 2021.x可正常编译通过

如何做

检查是否是由于其他版本依赖升级导致

Background

After upgrading the relevant dependencies of SpringBoot 3.0 , the unmodified code will also fail the checkstyle check, and 2021.x can work normally

How to do

Check whether it is caused by other version dependency upgrades

yuluo-yx commented 1 year ago

I want to try to solve this issue

yuluo-yx commented 1 year ago

Can you explain some more information? For example, which dependencies are used?

ruansheng8 commented 1 year ago

Can you explain some more information? For example, which dependencies are used?

见2022.x分支 , 将根目录中的maven-checkstyle-plugin插件取消注释 , 然后本地执行mvn validate , 将会看到代码检查无法通过 , 一样的代码在2021.x分支可以通过. 另外 , 如果本地mvn validate可以通过的话 , 尝试将一个源码文件改成不符合规范的格式 , 再次运行mvn validate看是否能看到预期的错误 (因为maven-checkstyle-plugin有可能没有生效)

yuluo-yx commented 1 year ago

Can you explain some more information? For example, which dependencies are used?

见2022.x分支 , 将根目录中的maven-checkstyle-plugin插件取消注释 , 然后本地执行mvn validate , 将会看到代码检查无法通过 , 一样的代码在2021.x分支可以通过. 另外 , 如果本地mvn validate可以通过的话 , 尝试将一个源码文件改成不符合规范的格式 , 再次运行mvn validate看是否能看到预期的错误 (因为maven-checkstyle-plugin有可能没有生效)

我clone了2021.x和2022.x两个版本,在2021中修改依赖,和2022中依赖相同,每修改一个pom依赖文件,我就运行一次mvn validate命令。我从头开始知道根目录的pom文件,2021版本还是Build SUCCESS

之后,我又尝试将2022版本中的依赖修改成2021中的依赖,2022版本运行mvn命令还是出错 FTT D4)R(JTQKTVYM(1BUK4

报错内容是 阻止标签必须按顺序显示:'[@param, @return, @throws, @since, @deprecated, @see]'。 [AtclauseOrder] 于是我在2022版本中修改@see@deprecated位置,又出现了新的报错 Line has leading space characters; indentation should be performed with tabs only. [RegexpSinglelineJava]

ruansheng8 commented 1 year ago

@yuluo-yx 是的 , 这个是目前存在的问题 . 根据我的观察 , 2021.x 和 2022.x 的checkstyle版本是一致的

yuluo-yx commented 1 year ago

@yuluo-yx 是的 , 这个是目前存在的问题 . 根据我的观察 , 2021.x 和 2022.x 的checkstyle版本是一致的

我查看了checkstyle官网介绍和github中issues没有找到有用的信息。 另外,checkstyle插件版本是在哪里声明的呢?根目录的pom.xml properties中没有找到相关的插件版本描述。

我自己加入了插件版本信息在代码里面,如下:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>checkstyle-validation</id>
                        <phase>validate</phase>
                        <goals>
……
  <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
        </plugins>
    </reporting>

在2021.x中写了相同的版本号。结果和之前一样,2021可以过,2022还是过不去。 不得不说,很离谱的问题!

ruansheng8 commented 1 year ago

@yuluo-yx 可以看一下控制台日志 , 会有 maven-checkstyle-plugin:3.1.2:checkreported by Checkstyle 9.2.1 with checkstyle.xml ruleset 相关日志信息 , 2021.x 和 2022.x 都是用的 9.2.1 的checkstyle

yuluo-yx commented 1 year ago

@yuluo-yx 可以看一下控制台日志 , 会有 maven-checkstyle-plugin:3.1.2:checkreported by Checkstyle 9.2.1 with checkstyle.xml ruleset 相关日志信息 , 2021.x 和 2022.x 都是用的 9.2.1 的checkstyle

我看到了版本信息。

jiachao23 commented 1 year ago

这个问题现在解决了吗?我能参与进来吗? @ruansheng8

steverao commented 1 year ago

这个问题现在解决了吗?我能参与进来吗? @ruansheng8

这个问题没有解决的,欢迎参与进来。

jiachao23 commented 1 year ago

@steverao 我昨天查看了一下代码,我就觉得可能是 spring-cloud-build 依赖版本升级导致的。2021.x 使用的是 3.1.5,2022.x 使用的是 4.0.0,我们可以查看这两个 pom 文件,2021.x 3.1.52022.x 4.0.0。这个里面定义的 maven-checkstyle-plugin 插件的版本虽然都是 3.1.2 ,但底层使用的 checkstyle 版本并不一致,2021.x 使用的是 8.43,2022.x 使用的是 9.2.1. 可以关注下面的代码

image

这两个 pom 文件中的 puppycrawl-tools-checkstyle.version 不一致

jiachao23 commented 1 year ago

另外,关于相同的文件会校验不通过,这个是 checkstyle 的一个 bug,这个 bug 在 8.44 中才解决。具体查看 https://github.com/checkstyle/checkstyle/issues/9941 , 可就是说 AtclauseOrderCheck 检查在 2021.x 中带有注解的方法上并没有生效。

jiachao23 commented 11 months ago

@steverao @ruansheng8

ruansheng8 commented 11 months ago

@steverao @jiachao23 从代码改动的角度来看, 把2022.x的checkstyle版本降低版本到和2021.x一样的版本似乎也不太合理, 只能手动修改一下2022.x的代码格式了 See #3362

ruansheng8 commented 11 months ago

@steverao 这里有一个点需要讨论一下, 是否需要升级2021.x的checkstyle版本, 从而来修复AtclauseOrderCheck这个bug, 让2021.x的代码风格和2022.x保持一致, 从而方便以后两个分支的部分代码同步

steverao commented 11 months ago

@steverao 这里有一个点需要讨论一下, 是否需要升级2021.x的checkstyle版本, 从而来修复AtclauseOrderCheck这个bug, 让2021.x的代码风格和2022.x保持一致, 从而方便以后两个分支的部分代码同步

我觉得这个主意挺好,可以把2021.x分支代码也改规范。