Spring Javaformat是Spring团队开发的一款基于Google Java Format的代码格式化工具,可以帮助Java开发者自动化进行代码格式化,提高代码质量,降低代码维护成本。

Spring Javaformat可以自定义配置文件,支持大量的代码风格配置选项,满足不同项目和团队的需求。还可以与Gradle、Maven、IntelliJ IDEA等常用开发工具集成使用,方便快速进行代码格式化。

此外,Spring Javaformat还支持CI/CD流程中的代码格式化,可以与Git、Jenkins等工具集成,确保在代码合并、构建和部署过程中,代码格式保持一致。

添加依赖

在你的基础项目的pom.xml文件中,添加javaformat的依赖

<!--代码格式插件,默认使用spring 规则 ./mvnw spring-javaformat:apply -->
<plugin>
    <groupId>io.spring.javaformat</groupId>
    <artifactId>spring-javaformat-maven-plugin</artifactId>
    <version>${spring.checkstyle.plugin}</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <inherited>true</inherited>
            <goals>
                <goal>validate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

代码格式化

  • 可以使用命令行工具进行格式化./mvnw spring-javaformat:apply
  • 也可以使用项目下的插件spring-javaformat:apply,如图:
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/lori/p/17477997.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程