參考環境
Linux version 4.10.0-19-generic
Ubuntu 17.04
IntelliJ IDEA 2020.1(Ultimate Edition)
jdk-8u212-linux-x64
導入項目
在Idea中依次選擇 File -> New -> Project from Existing Sources…
在文件夾中選擇項目根目錄下的 build.gradle 文件
在 Import Project from Gradle 窗口選擇 use gradle wrapper task configuration
(根據Idea版本不同,窗口可能出現在編輯器右下角)
創建 run configuration
將項目根目錄下 intellij_configs 文件夾下的 runConfigurations 複製到 .idea 文件夾下
在項目根目錄下執行以下代碼:
cp -r intellij_configs/runConfigurations .idea
導入代碼格式設置
在Idea中依次選擇 File -> Settings -> Editor -> Code Style -> Java -> Manage(鋸齒形圖標) -> Import Scheme -> IntelliJ IDEA code style XML
在文件夾中選擇項目根目錄下 intellij_configs 文件夾下的 graphflow_code_style_guide.xml 文件
導入之後使用快捷鍵 Alt + Shift + L 可以格式化代碼
代碼檢查
在Idea中依次選擇 Analyze -> Inspect Code… -> Profile (Inspection profile 後面的3個小點) -> Manage(鋸齒形圖標) -> Import profile…
在文件夾中選擇項目根目錄下 intellij_configs 文件夾下的 graphflow_inspections.xml 文件
導入之後Idea會高亮不符合代碼格式規範的代碼
可能的問題及解決方法
問題1:build 的時候出現如下錯誤提示
Exception in thread “main” java.lang.NoClassDefFoundError: io/grpc/BindableService
解決方法:Idea 版本過低,將Intellij Idea 版本更新到 2017+ 的版本
問題2:代碼中所有get和set方法報錯
解決方法:在 Idea 中安裝插件 lombok,具體操作過程可參見 Lombok插件安裝
(tip:較高版本編譯器安裝Lombok插件後不需要添加Maven依賴)