1、STS與P3C集成
1)模版導(dǎo)入
阿里規(guī)范提供的有2個(gè)代碼模版文件,導(dǎo)入到sts中
Window>>Preferences>>Java>>Code Style
選中Code Template,導(dǎo)入p3c-codetemplate.xml

選中formatter,導(dǎo)入p3c-codestyle.xml

2)插件安裝
Help >> Install New Software>>add

點(diǎn)擊OK

選中插件,繼續(xù)

點(diǎn)擊下一步

接受協(xié)議,點(diǎn)擊Finish

中間可能會(huì)提示,選擇Install anyway

安裝完成,重啟
3)使用方法
Window>>Show View>>Others,選擇SmartFoxViews,點(diǎn)擊Open

P3C Results和Rule Detail面板會(huì)出現(xiàn)在當(dāng)前視圖上

以一個(gè)Springboot Demo工程為例,在項(xiàng)目上包上或者類上右鍵點(diǎn)擊,阿里編碼規(guī)約掃描

在項(xiàng)目上包上或者類上

掃描后會(huì)有相應(yīng)的提示標(biāo)識(shí)和詳細(xì)信息,還可迅速定位解決。
2、IDEA與P3C集成
1)模版導(dǎo)入
File>>Settings>>Code Style>>Java>>Import Schema
導(dǎo)入CodeStyle

選中formatter,導(dǎo)入p3c-codestyle.xml
2)插件安裝
File>>Settings>>Plugins>>Browser repositories

點(diǎn)擊Install安裝插件,安裝完成后重啟IDEA
如果在線安裝不成功,可以手動(dòng)下載插件zip包,然后Install plugin from disk,從本地安裝插件
下載地址:https://plugins.jetbrains.com/plugin/10046-alibaba-java-coding-guidelines

選擇zip文件,安裝

3)使用方法
項(xiàng)目或包或類上,點(diǎn)擊右鍵

編碼規(guī)約掃描

掃描結(jié)果展示如上圖