EditorConfig Maven Plugin 的用法

EditorConfig 帮助开发人员在不同的编辑器和 IDE 之间定义和维护一致的编码样式。

EditorConfig helps maintain consistent coding styles for multiple
developers working on the same project across various editors and IDEs. The EditorConfig project
consists of a file format for defining coding styles and a collection of text editor plugins
that enable editors to read the file format and adhere to defined styles. EditorConfig files are
easily readable and they work nicely with version control systems.

editorconfig-maven-plugin is a Maven plugin for checking whether project files comply with format rules defined
in .editorconfig files and eventually also for fixing the violations.

官方文档:

快速使用

1)在你的 Spring Boot 项目根目录中添加 .editorconfig 文件:

# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# https://editorconfig.org/

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 4

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

2)在你的 Spring Boot 项目中集成插件管理(Kaddo-框架已集成插件管理,开发者可以跳过):

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.ec4j.maven</groupId>
        <artifactId>editorconfig-maven-plugin</artifactId>
        <version>${editorconfig-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>check</id>
            <phase>verify</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <excludes>
            <!-- Note that maven submodule directories and many non-source file patterns are excluded by default -->
            <!-- You can exclude further files from processing: -->
            <!-- <exclude>src/main/**/*.whatever</exclude> -->
          </excludes>
          <!-- All files are included by default: -->
          <!-- <includes> -->
          <!--   <include>**</include> -->
          <!-- </includes> -->
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

3)在你的 Spring Boot 项目中使用插件:

<build>
  <plugins>
    <plugin>
      <groupId>org.ec4j.maven</groupId>
      <artifactId>editorconfig-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

4)执行命令(会自动处理代码格式):

mvn editorconfig:format
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值