【发布时间】:2022-07-11 08:19:51
【问题描述】:
除了 .java 文件之外,我有很多包含 .json 文件的 Spring Boot 项目。
对于 java 格式,我们使用带有 google-java-format 的预提交钩子。但是,对于格式化 .json 文件,我有点吃力。
我使用了一个 maven 一尘不染的插件
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<formats>
<format>
<includes>
<include>*.json</include>
</includes>
<prettier>
<!-- Specify at most one of the following 3 configs: either 'prettierVersion' (2.0.5 is default) , 'devDependencies' or 'devDependencyProperties' -->
<prettierVersion>2.0.5</prettierVersion>
<!-- Specify config file and/or inline config, the inline always trumps file -->
<config>
<useTabs>true</useTabs>
</config>
</prettier>
</format>
</formats>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
这种方法的问题是,它需要在机器中安装npm,否则mvn clean install 将失败。 jenkins 服务器上的许多机器没有预先安装 npm,因此在构建过程中会失败。
有没有简单的方法来解决这个问题? PS:本项目这里使用GIT作为版本控制。
【问题讨论】: