{"id":10020422,"date":"2024-11-28T13:44:31","date_gmt":"2024-11-28T05:44:31","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020422"},"modified":"2024-11-28T13:44:31","modified_gmt":"2024-11-28T05:44:31","slug":"java%e4%bb%a3%e7%a0%81%e4%b9%8b%e7%be%8e%ef%bc%8c%e4%bb%8e%e9%81%b5%e5%be%aa%e6%a0%b7%e5%bc%8f%e8%a7%84%e8%8c%83%e5%bc%80%e5%a7%8b","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020422","title":{"rendered":"Java\u4ee3\u7801\u4e4b\u7f8e\uff0c\u4ece\u9075\u5faa\u6837\u5f0f\u89c4\u8303\u5f00\u59cb"},"content":{"rendered":"<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u96f6\u552e \u5218\u4ef2\u4f1f<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509610\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n<\/p>\n<p>\u5728\u8f6f\u4ef6\u5f00\u53d1\u7684\u4e16\u754c\u91cc\uff0c\u4ee3\u7801\u4e0d\u4ec5\u662f\u7a0b\u5e8f\u7684\u57fa\u77f3\uff0c\u66f4\u662f\u7a0b\u5e8f\u5458\u4ea4\u6d41\u7684\u901a\u7528\u8bed\u8a00\u3002\u800cJava\uff0c\u4f5c\u4e3a\u4e00\u95e8\u5e7f\u6cdb\u5e94\u7528\u4e8e\u4f01\u4e1a\u7ea7\u5e94\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5176\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u4e00\u81f4\u6027\u5bf9\u4e8e\u9879\u76ee\u7684\u957f\u671f\u7ef4\u62a4\u548c\u56e2\u961f\u534f\u4f5c\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u5c06\u5e26\u4f60\u63a2\u7d22Java\u4ee3\u7801\u7684\u7f8e\u5b66\uff0c\u63ed\u793a\u90a3\u4e9b\u80fd\u591f\u8ba9\u4f60\u7684\u4ee3\u7801\u65e2\u7f8e\u89c2\u53c8\u9ad8\u6548\u7684\u6837\u5f0f\u89c4\u8303\u3002\u65e0\u8bba\u662f\u521d\u51fa\u8305\u5e90\u7684\u65b0\u624b\u8fd8\u662f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u8001\u624b\uff0c\u90fd\u80fd\u4ece\u4e2d\u83b7\u5f97\u7075\u611f\uff0c\u63d0\u5347\u7f16\u7801\u7684\u827a\u672f\u3002<\/p>\n<h2>\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u4ee3\u7801\u6837\u5f0f\u89c4\u8303<\/h2>\n<p>\u5bf9\u4e8e\u56e2\u961f\u5f00\u53d1\uff0c\u4e0d\u540c\u7684\u4ee3\u7801\u89c4\u8303\u6216\u4e0d\u89c4\u8303\u53ef\u80fd\u5f15\u8d77\u7684\u95ee\u9898\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<\/p>\n<p>1.\u4ee3\u7801\u53ef\u8bfb\u6027\uff0c\u4ee3\u7801\u662f\u4e3a\u4e86\u4eba\u9605\u8bfb\u7684\uff0c\u4e0d\u662f\u53ea\u4e3a\u4e86\u673a\u5668\u6267\u884c\uff1b<\/p>\n<p>2.\u4ee3\u7801format\u5f15\u53d1\u7684\u5927\u91cf\u7684diff\uff0c\u5e72\u6270code review\uff1b<\/p>\n<p>3.\u95f4\u63a5\u5f71\u54cd\u4ee3\u7801\u8d28\u91cf\u548c\u56e2\u961f\u534f\u4f5c\u6548\u7387\uff1b<\/p>\n<p>\u5728\u654f\u6377\u8fed\u4ee3\u7684\u8f6f\u4ef6\u5f00\u53d1\u73af\u5883\u4e2d\uff0c\u826f\u597d\u7684\u4ee3\u7801\u89c4\u8303\u4e0d\u4ec5\u80fd\u591f\u5e2e\u52a9\u56e2\u961f\u6210\u5458\u5feb\u901f\u7406\u89e3\u5f7c\u6b64\u7684\u4ee3\u7801\uff0c\u51cf\u5c11\u6c9f\u901a\u6210\u672c\uff0c\u8fd8\u80fd\u5728\u4ee3\u7801\u7ef4\u62a4\u548c\u6269\u5c55\u65f6\u8282\u7701\u5b9d\u8d35\u7684\u65f6\u95f4\u3002\u6b64\u5916\uff0c\u4e00\u81f4\u7684\u4ee3\u7801\u98ce\u683c\u4e5f\u662f\u9879\u76ee\u4e13\u4e1a\u6027\u7684\u4f53\u73b0\uff0c\u80fd\u591f\u7ed9\u4ee3\u7801\u5ba1\u67e5\u8005\u548c\u672a\u6765\u7684\u7ef4\u62a4\u8005\u7559\u4e0b\u826f\u597d\u7684\u7b2c\u4e00\u5370\u8c61\u3002<\/p>\n<\/p>\n<h2>\u4e8c\u3001<strong>\u63a2\u7d22Java\u4ee3\u7801<\/strong>\u89c4\u8303<\/h2>\n<p>\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8Java\u793e\u533a\u5e7f\u6cdb\u8ba4\u53ef\u7684\u7f16\u7801\u89c4\u8303\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8eGoogle Java Style\u548cOracle\u5b98\u65b9\u7684\u7f16\u7801\u6307\u5357\u3002\u4ece\u547d\u540d\u7ea6\u5b9a\u3001\u4ee3\u7801\u683c\u5f0f\u5316\u3001\u6ce8\u91ca\u7684\u4f7f\u7528\uff0c\u5230\u9519\u8bef\u5904\u7406\u548c\u6d4b\u8bd5\u4ee3\u7801\u7684\u7f16\u5199\uff0c\u6bcf\u4e00\u4e2a\u7ec6\u8282\u90fd\u662f\u6784\u5efa\u9ad8\u8d28\u91cfJava\u4ee3\u7801\u7684\u5173\u952e\u3002<\/p>\n<h3>2.1 \u4e1a\u754cJava\u4ee3\u7801\u6837\u5f0f\u89c4\u8303<\/h3>\n<h4>a. Google Java Style<\/h4>\n<p>Google\u5728github\u4e0a\u7ef4\u62a4\u7684\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u7684\u4ee3\u7801\u89c4\u8303\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=gHwgFy1Ga84en3%2BOzMth0w%3D%3D.k5AYMBUs7VQGXV%2FJ7%2Br%2FYo0QnS0DQoGdjaI6cXXkTcB3mRa1npph30nvY%2BbAQvh4\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/google\/styleguide<\/a>\uff0c\u5176\u4e2d\uff1a<\/p>\n<p>\u2022<a href=\"https:\/\/link.segmentfault.com\/?enc=qz%2F2ECYEfDcxn%2Bs6gHliSQ%3D%3D.y7NGxn9mqNj7BlcG1FRRL%2Fs0yr%2FqjknT1GqOvkI7shT5%2FUpJQ4UqGqgzbNF4U6mHKFmC158kb08K9NFkYlBD5A%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">javaguide.html<\/a> \u662fGoogle\u5bf9Java\u7f16\u7a0b\u8bed\u8a00\u4ee3\u7801\u7f16\u7801\u6807\u51c6\u7684\u5b8c\u6574\u5b9a\u4e49\uff1b<\/p>\n<p>\u2022<a href=\"https:\/\/link.segmentfault.com\/?enc=ETxhwzciZO1owJr7ipylgQ%3D%3D.PMvbjzEBXl4%2BZHlYk5K5a%2FwONNYrqCdvwalU63wuVO5BRmpMUBTvcK8xHdM8iJruqQ61nd3rU6LNUkCfLp%2BMx9Lf9hhwt58ZP7bO6GUn15lx8elqkYh4IrtNtvCCctwj\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">intellij-java-google-style.xml<\/a> \u662fGoogle Java\u4ee3\u7801\u89c4\u8303\u6587\u4ef6\uff0c\u9002\u7528\u4e8eIntellij IDEA\u5f00\u53d1\u5de5\u5177\uff1b<\/p>\n<h4>b. \u963f\u91ccJava\u89c4\u8303<\/h4>\n<p>\u963f\u91cc\u5728 GitHub \u4e0a\u6709\u4e00\u4e2a\u5173\u4e8e Java \u5f00\u53d1\u89c4\u8303\u7684\u4ed3\u5e93 p3c\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=Qs3n4IJ7aU6qM6xwU5glfA%3D%3D.%2BmgfjGWg%2FHbwN5UQG04PTUg0yIF0yD5clIIjL2Xw%2FkA%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/alibaba\/p3c\uff0c<\/a>\u5176\u4e2d\uff1a<\/p>\n<p>\u2022<a href=\"https:\/\/link.segmentfault.com\/?enc=WhHF58PTDJ5tcNnddx2EMw%3D%3D.qbE6GxYNXJXwOwOr0uSql6sq9d5XIRl2Whg%2BVAvT46rKD0CBmEP9SQeJLUoRcAcIV3LivkKWc6IbMb40cjNe2oN8248XmWlRQW%2BzD4Akir3nm0cFfwxVlzzqdkkYDnnoy3QDebl6CpvI63c139llYbLstDi81enFar9wVdlkRKyazVqu9e%2BuXjpRf8L1gL5Q3ItfUw9CIMlXpRLQu1LQtZKMwX1HB%2FqMI19yAOe%2FMdkCU17rp%2BqnB5IuEn%2FwXrQs\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Java\u5f00\u53d1\u624b\u518c(\u9ec4\u5c71\u7248).pdf<\/a> \u8986\u76d6\u7f16\u7a0b\u89c4\u7ea6\u3001\u5f02\u5e38\u65e5\u5fd7\u3001\u5355\u5143\u6d4b\u8bd5\u7b49\u4e03\u4e2a\u7ef4\u5ea6\uff1b<\/p>\n<p>\u2022<a href=\"https:\/\/link.segmentfault.com\/?enc=xqnR32qHZq7QUyOXaRSijw%3D%3D.eTdJk17HYpIFMOyMGQRd8U2lkrrG%2BnDRXpHcBGIDrVsdhLMixvi0GH6k2C8XhSF%2FCydaNbDEQtHTtbQkazvBV2jhypRlptBokVE8srFbL94%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Alibaba Java Coding Guidelines<\/a> Jetbrains\u63d2\u4ef6\u5e02\u573a\u63d0\u4f9b\u7684\u4ee3\u7801\u6307\u5bfc\u63d2\u4ef6\uff0c<a href=\"https:\/\/link.segmentfault.com\/?enc=JXdDdYtQb6DaMPozInJJ8w%3D%3D.feUiIwVuPqrWgGAEv4PN0QlYX%2Fnl8iqWd03zG8IAzEOrkq6mLAhOeJ%2F0ppJrPxcKnDg21AJnn%2BdEUJg7%2FX6z%2Bgk7xTrQld7%2BO9kauK2sVo8%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"> idea-plugin<\/a> \u63d0\u4f9b\u7f16\u8bd1\u3001\u5b89\u88c5\u3001\u4f7f\u7528\u624b\u518c\uff1b<\/p>\n<h4>c. \u5176\u5b83\u89c4\u8303<\/h4>\n<table>\n<thead>\n<tr>\n<th><strong>\u516c\u53f8\/\u7ec4\u7ec7<\/strong><\/th>\n<th><strong>Style Guide<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Sun\/Oracle<\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=8BIv1gqGYuq%2BBjNpu0%2F16g%3D%3D.xMFiC6IicB1j5pFruNCBCyG88eSP%2BJ4FubJuR3yEKiOOlAFJ%2BLl8L5smJxWE3P1aUYZkjhi5ucioY0V0utfWxA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">The Original Sun Java Style Guide<\/a><\/td>\n<\/tr>\n<tr>\n<td>Andriod<\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=bPPUWBFWyV1IHF%2FKxiF7pg%3D%3D.JDEKElIZ8G9vST3CZ1eqcwobNOLURqGcyL6OZPiQCQUvw7z3Xyb2p3NwKZq%2BqiFMxXmPvG2ejfOnFiKuOOuXUQ%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Android Open Source Project (AOSP) Style Guide<\/a><\/td>\n<\/tr>\n<tr>\n<td>Twitter<\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=yYD4pEtfoMaTeke0sbmrKQ%3D%3D.ywww60HaqiQ2f4atpDE6fyzEFakOgC%2BRt9ej2fkXjRQmiPzYl%2B7C8ge2Dkz3Zau44mvPIaMRDI5NSp2ufAQn64WlRxFsVJo6LjwxxmA%2BJKg3Mt3384I86FLemZSfbhze\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Twitter\u2019s Java Style Guide<\/a><\/td>\n<\/tr>\n<tr>\n<td>Coderanch<\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=aPeaiV5Amnf2gtzqvj8znw%3D%3D.Gom1iaF6OCJ8FdiF2WGa8Agb5XJ4Ms7duiGbL27%2Bj%2FdVRhPrP0BWcUO1tL6pVX51\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">The CodeRanch Style Guide<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.2 \u89c4\u8303\u9009\u62e9\u4e0e\u5236\u5b9a<\/h3>\n<h4>a. \u89c4\u8303\u9009\u62e9<\/h4>\n<p>\u4e0a\u9762\u5217\u4e3e\u4e86\u591a\u9879\u4ee3\u7801\u89c4\u8303\uff0c\u5728\u51b3\u5b9a\u4f7f\u7528\u54ea\u79cd\u89c4\u8303\u4e4b\u524d\uff0c\u53ef\u4ee5\u8003\u8651\u4e09\u4e2a\u65b9\u9762\uff1a<\/p>\n<p>\u2022\u660e\u786e\u76ee\u6807\uff1a\u4f7f\u7528\u4ee3\u7801\u89c4\u8303\u7684\u76ee\u7684\u662f\u4ec0\u4e48\uff0c\u53ea\u662f\u4e3a\u4e86\u9879\u76ee\u5185\u4ee3\u7801\u98ce\u683c\u4e00\u81f4\uff0c\u8fd8\u662f\u4e3a\u4e86\u548c\u5176\u4ed6\u56e2\u961f\u5206\u4eab\u6216\u8005\u5176\u4ed6\u516c\u53f8\u5206\u4eab\u6216\u8005\u5f00\u6e90\uff1f<\/p>\n<p>\u2022\u4f7f\u7528\u73af\u5883\uff1a\u5f00\u53d1\u9605\u8bfb\u4ee3\u7801\u7684\u73af\u5883\u662f\u4ec0\u4e48\uff0cGitHub\u3001GitLab\u3001\u516c\u53f8\u5185\u90e8\u7684Coding\uff1f<\/p>\n<p>\u2022\u5de5\u5177\u652f\u6301\uff1acode format\u5de5\u5177\u652f\u6301\u60c5\u51b5\uff0ccode sytle check\u5de5\u5177\u652f\u6301\u60c5\u51b5\uff0c\u7f16\u8bd1\u5de5\u5177\uff1amaven\u3001gradle\uff0cIDE\uff1aIntelliJ\u3001Eclipse\u3001VS Code\uff1b<\/p>\n<p>\u7efc\u5408\u4e0a\u9762\u7684\u4e09\u4e2a\u65b9\u9762\u7684\u8003\u8651\uff0c\u4f18\u5148\u9009\u62e9Google Java Style\u3002<\/p>\n<h4>b. \u89c4\u8303\u5236\u5b9a<\/h4>\n<p>Google Java Style\u90e8\u5206\u4ee3\u7801\u6837\u5f0f\u56e2\u961f\u96be\u4ee5\u63a5\u53d7\uff0c\u6bd4\u59822\u7a7a\u683c\u7f29\u8fdb\u7b49\uff0c\u53ef\u4ee5\u5728\u539f\u59cbGoogle Java Style\u57fa\u7840\u4e0a\uff0c\u9002\u5f53\u5b9a\u5236\u5316\u8c03\u6574\u3002<\/p>\n<p>\u2022\u4fee\u6539intellij-java-google-style.xml\u4e2d\u7684\u5185\u5bb9\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>option<\/th>\n<th>previous value<\/th>\n<th>modified value<\/th>\n<th>note<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>INDENT\/_SIZE<\/td>\n<td>2<\/td>\n<td>4<\/td>\n<td>\u884c\u7f29\u8fdb\u7a7a\u683c\u6570<\/td>\n<\/tr>\n<tr>\n<td>TAB\/_SIZE<\/td>\n<td>2<\/td>\n<td>4<\/td>\n<td>TAB\u7a7a\u683c\u6570<\/td>\n<\/tr>\n<tr>\n<td>CONTINUATION\/_INDENT\/_SIZE<\/td>\n<td>4<\/td>\n<td>8<\/td>\n<td>\u6362\u884c\u7f29\u8fdb\u7a7a\u683c\u6570<\/td>\n<\/tr>\n<tr>\n<td>RIGHT\/_MARGIN<\/td>\n<td>100<\/td>\n<td>120<\/td>\n<td>\u5355\u884c\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>JD\/_PRESERVE\/_LINE\/_FEEDS<\/td>\n<td>\u65e0<\/td>\n<td>TRUE<\/td>\n<td>JavaDoc \u4e2d\uff0c\u4fdd\u7559\u624b\u52a8\u7684\u6362\u884c<\/td>\n<\/tr>\n<tr>\n<td>KEEP\/_LINE\/_BREAKS<\/td>\n<td>\u65e0<\/td>\n<td>TRUE<\/td>\n<td>Java\u4ee3\u7801\u4e2d\uff0c\u4fdd\u7559\u624b\u52a8\u7684\u6362\u884c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2022\u4fee\u6539intellij-java-jd-style.xml\u6587\u4ef6\u4e0b\u8f7d\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=WxwDIXv7TeZ87fMMe45lZA%3D%3D.E0LpJQsq0qoECrYPLLuHG8iR4dEmGwL4rkcCWB3RLwUCABhkYxyk8QowJD4xl%2BQgUPhdId%2BI%2FrZo7JFF883nqsUKg229X%2F4OXmQYLu1SelzodTqG8UIry1oLw2JZrZk838GBbAWVaCXjj%2FpU9VLjYQ%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">http:\/\/xingyun.jd.com\/codingRoot\/liuzhongwei18\/styleguide\/blo&#8230;<\/a><\/p>\n<h3>2.3 \u89c4\u8303\u4f7f\u7528<\/h3>\n<p>\u4ee3\u7801\u6837\u5f0f\u89c4\u8303\u7684\u4f7f\u7528\u5206\u4e3a\u4e24\u4e2a\u65b9\u9762\uff1a<\/p>\n<p>\u2022\u4ee3\u7801\u683c\u5f0f\u5316<\/p>\n<p>\u2022\u4ee3\u7801\u6837\u5f0f\u6821\u9a8c<\/p>\n<table>\n<thead>\n<tr>\n<th>\u89c4\u8303\u4f7f\u7528<\/th>\n<th>\u82f1\u6587<\/th>\n<th>\u4f7f\u7528\u5bf9\u8c61<\/th>\n<th>\u4f7f\u7528\u65b9\u5f0f<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u914d\u7f6e\u6587\u4ef6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4ee3\u7801\u683c\u5f0f\u5316<\/td>\n<td>code style<\/td>\n<td>\u5f00\u53d1\u8005<\/td>\n<td>IDE\u624b\u52a8<\/td>\n<td>\u5b9a\u4e49\u4ee3\u7801\u98ce\u683c<\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=GQJ6icXKUkoHs9Tfw0yubg%3D%3D.TQOg1VMOfWZm7yV%2Fpj5QV85kjtogTOS9VRn8nEo1B92A3GCSapilVr829Z7aRal36YS8Z%2BvpY7ibBgkDJ3QIynAw%2FC%2BBvK4Z4goSnr8gUg4Nrb2UuvjlcXomBYvELUtB1T2xUso2JhzvXHR3YFcXGw%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">intellij-java-jd-style.xml<\/a><\/td>\n<\/tr>\n<tr>\n<td>\u4ee3\u7801\u6837\u5f0f\u6821\u9a8c<\/td>\n<td>check style<\/td>\n<td>\u56e2\u961f<\/td>\n<td>\u81ea\u52a8\u5316<\/td>\n<td>\u6821\u9a8c\u4ee3\u7801\u98ce\u683c<\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=7F94ys1g%2BawIeWoavZCPrQ%3D%3D.%2Blv2f2aW7gelMtRxCVl3eZHIPwHVpRgaPLgIDDvGBLTkuUmkr6cbUMdEQjBpn8ELJEbTHcU3NvKb64%2FH5VAG3FEiH0RgWHb9wsaNJDf%2BI0MTh%2BU3Y%2FDW4UtTny6UWEGn\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">checkstyle.xml<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f\uff1acode style \u8ddf check style \u7684\u300c\u914d\u7f6e\u6587\u4ef6\u300d\u5fc5\u987b\u5bf9\u5e94\uff0c\u5373\u6309\u7167code style format\u7684\u4ee3\u7801check style\u4e0d\u62a5\u9519\u3002<\/p>\n<h4>\u4ee3\u7801\u6837\u5f0f\u6821\u9a8c<\/h4>\n<p>\u4ee3\u7801\u683c\u5f0f\u5316\u4f9d\u8d56\u4e8e\u5f00\u53d1\u8005\u624b\u52a8\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u4e3a\u8fbe\u5230\u56e2\u961f\/\u9879\u76ee\u4ee3\u7801\u6837\u5f0f\u89c4\u8303\u7684\u843d\u5730\uff0c\u9700\u8981\u6709\u5168\u9762\u7684\u81ea\u52a8\u5316\u7684\u4ee3\u7801\u68c0\u67e5\u3002\u6839\u636e\u5f53\u524d\u4e1a\u754c\u63a8\u8350\uff0c\u91c7\u7528Checkstyle\u4f5c\u4e3a\u81ea\u52a8\u5316\u4ee3\u7801\u6837\u5f0f\u6821\u9a8c\u5de5\u5177\u3002<\/p>\n<p>\u9700\u8981\u5bf9\u539f\u59cb Google Code Style \u7684<a href=\"https:\/\/link.segmentfault.com\/?enc=eRyAauvDSSUxuIPc201B%2FA%3D%3D.7VReDxb6K4CHxEW%2BBwao6TbiVBJP04Q1aBx6bj3sIyCJRUS0rfXZV8m1FhEK%2FjYXlEKxCTljsVtbrfoQ17KatTckZIeBIu7CzI1GRdKZAKFtEP6BuEqHce5oZpYDJ%2BEP\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">google\/_checks<\/a>\u8fdb\u884c\u5b9a\u5236\uff0c\u4ee5\u9002\u914d\u4e0a\u9762<a href=\"https:\/\/link.segmentfault.com\/?enc=vLZvDKvDdlmL128l81RqOQ%3D%3D.9g1IZ0M5XfpfNmdWHo1ulffvhh80mBnRB3rbYObxDyy7eeMr0ovEcV%2BMuFB58oKBFfSztZPbUVC2p2QEl216a4RqcRTiVeu2pVluiNMJRonZs6ML%2BKtA5lP%2F6B2zqb5sSv%2FXpegSiR5GFiP2D6R5bQ%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">intellij-java-jd-style.xml<\/a>\u7684\u5b9a\u5236\u3002<\/p>\n<p>\u2022\u4fee\u6539<a href=\"https:\/\/link.segmentfault.com\/?enc=2bENmSkkRfQdu4pgpkbkVA%3D%3D.bDDD2E0rtIXb0olP%2FmVi8aqgqaJ%2FVXLUnACkgtD2rZqOqdgutDQ6JSPcFhD5D7Opo5OhuJ3YL%2BvjcCTk0lqHn7kiUhEabWgH9UXNV%2FiSAx6yBfIyaJFpeOygWhfajXDF\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">google\/_checks<\/a>\u4e2d\u7684\u5185\u5bb9\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>module<\/th>\n<th>property<\/th>\n<th>previous value<\/th>\n<th>modified value<\/th>\n<th>note<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>LineLength<\/td>\n<td>max<\/td>\n<td>100<\/td>\n<td>120<\/td>\n<td>\u5355\u884c\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>Indentation<\/td>\n<td>basicOffset braceAdjustment caseIndent throwsIndent lineWrappingIndentation arrayInitIndent<\/td>\n<td>2 2 2 4 4 2<\/td>\n<td>4 0 4 4 4 4<\/td>\n<td>\u4f7f\u7528checkstyle\u9ed8\u8ba4\u7f29\u8fdb\u98ce\u683c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2022\u4fee\u6539checkstyle.xml\u6587\u4ef6\u4e0b\u8f7d\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=hKiG3%2F81QT4GjMvcNU%2B50g%3D%3D.EePdj6pT6qa0uKfXruEaPaofbWFx8CsZazIcc0AJsqHO3hiumPxGyiiMdR%2Fu86KpugLxUDOdNQ%2FHe6%2BiAwuSl4%2BGqhfVxmGwd8tfdBm6V9WcV7J%2B3dkkqpjCasbLd632\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">http:\/\/xingyun.jd.com\/codingRoot\/liuzhongwei18\/styleguide\/blo&#8230;<\/a><\/p>\n<\/p>\n<p>\u9664\u4e86\u4e0a\u8ff0\u7684\u957f\u5ea6\u548c\u7f29\u8fdb\u7684\u4ee3\u7801\u6837\u5f0f\u6821\u9a8c\uff0cCheckstyle\u8fd8\u53ef\u4ee5\u914d\u7f6e\u5176\u5b83\u4ee3\u7801\u6821\u9a8c\uff0c\u53ef\u6839\u636e\u56e2\u961f\u63a5\u53d7\u60c5\u51b5\u4e88\u4ee5\u914d\u7f6e\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>module<\/th>\n<th>property<\/th>\n<th>default value<\/th>\n<th>note<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>FileLength<\/td>\n<td>max<\/td>\n<td>2000<\/td>\n<td>\u5355\u4e2a\u6587\u4ef6\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>MethodLength<\/td>\n<td>max<\/td>\n<td>150<\/td>\n<td>\u5355\u4e2a\u65b9\u6cd5\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>ParameterNumber<\/td>\n<td>max<\/td>\n<td>7<\/td>\n<td>\u65b9\u6cd5\u7684\u53c2\u6570\u4e2a\u6570<\/td>\n<\/tr>\n<tr>\n<td>ModifierOrder<\/td>\n<td><\/td>\n<td><\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=PS1%2FMkwq37tlqcf4k9iI%2FQ%3D%3D.osbkEQdc4TVLtgA%2F0b2mmTIojSGudXBz6ZTfexybuaC51kN%2FX0cg%2FGBZPVGxHzeHUX4M%2BgYmFc21%2F8H%2FKszN1SA%2F3xtdV%2Bhyv%2F6%2Fn5aUp3GalWqO%2FeI8ccwl1xDS4Umu\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Java\u8bed\u8a00\u89c4\u8303<\/a><\/td>\n<\/tr>\n<tr>\n<td>NestedIfDepth<\/td>\n<td>max<\/td>\n<td>1<\/td>\n<td>\u68c0\u67e5if-else\u5d4c\u5957\u5c42\u6570<\/td>\n<\/tr>\n<tr>\n<td>NestedTryDepth<\/td>\n<td>max<\/td>\n<td>1<\/td>\n<td>\u68c0\u67e5try-catch-finally\u5d4c\u5957\u5c42\u6570<\/td>\n<\/tr>\n<tr>\n<td>ReturnCount<\/td>\n<td>max<\/td>\n<td>2<\/td>\n<td>\u4e00\u4e2a\u65b9\u6cd5\u6700\u591a\u6709return\u7684\u6570\u91cf<\/td>\n<\/tr>\n<tr>\n<td>CyclomaticComplexity<\/td>\n<td>max<\/td>\n<td>10<\/td>\n<td>\u65b9\u6cd5\u5708\u590d\u6742\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>MagicNumber<\/td>\n<td><\/td>\n<td><\/td>\n<td>\u68c0\u67e5\u9b54\u6cd5\u6570\u5b57\uff0c\u672a\u88ab\u5b9a\u4e49\u4e3a\u5e38\u91cf\u7684\u6570\u503c<\/td>\n<\/tr>\n<tr>\n<td>&#8230;<\/td>\n<td><\/td>\n<td><\/td>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=01qzpNaCH%2BA9QgtzUh%2B%2F7A%3D%3D.%2FbNfeJ2kVlPghS5ojka0J%2F%2FG7JxQN1KQXKB8%2Fjzj%2FG6JyEhDPCErpiYMIHqKPtIs\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/checkstyle.org\/checks.html<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e09\u3001<strong>\u6700\u4f73\u5b9e\u8df5\uff1a\u5982\u4f55\u5c06\u89c4\u8303\u878d\u5165\u65e5\u5e38\u5f00\u53d1<\/strong><\/h2>\n<h3>3.1 code style\u914d\u7f6e&#038;\u4f7f\u7528<\/h3>\n<h4>a. IDEA\u914d\u7f6ecode style<\/h4>\n<p>\u5728 IntelliJ IDEA\u4e0b\uff0c\u4f7f\u7528<code>intellij-java-jd-style.xml<\/code>\u8fdb\u884c\u4ee3\u7801\u683c\u5f0f\u5316\u4e4b\u524d\uff0c\u9700\u8981\u5148\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<p>\u8bbe\u7f6e\u914d\u7f6e\u6587\u4ef6\uff0c\u8def\u5f84\uff1a<code>IntelliJ IDEA<\/code>\u2192<code>Preference<\/code>\u2192<code>Editor<\/code>\u2192<code>Code Style<\/code>\uff0c\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n<p>\u5bfc\u5165\u5b9a\u5236\u7684code style\u6587\u4ef6\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=4v3Fbymsj7xKITVVjfSuVg%3D%3D.DZ7LJcF9l7aGDE9quhRILnrUBR39OJEzWFzVr7AtyGqoWhfKD4IKoDryUTn6f7Fo0RV6Xy%2Fdug2LQ6DEeIcrPl5BsztKYEPF09RSOTUO22hAPmr1GfE5HFRfW0RY9Mj70qeX%2FdSW3PqEmf2krSxLVg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">intellij-java-jd-style.xml<\/a><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509611\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<\/p>\n<p>\u547d\u540dScheme\uff0c\u5982\u56fe\u4e2dJD-Style\uff0c\u5e76\u542f\u7528\u8be5\u4ee3\u7801\u6837\u5f0f\u89c4\u8303<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509612\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h4>b. IDEA\u4f7f\u7528code style<\/h4>\n<p>\u5b8c\u6210\u4e0a\u8ff0\u914d\u7f6e\u540e\uff0c\u5728Mac\u73af\u5883\u7684IntelliJ IDEA\u4e2d\uff0c\u53ef\u4ee5\u5bf9\u9009\u4e2d\u7684\u4ee3\u7801\u683c\u5f0f\u5316\uff08\u5feb\u6377\u952e\uff1aOption+Command+L\uff09\u6216\u8005\u5bf9\u9009\u4e2d\u7684\u6587\u4ef6\u683c\u5f0f\u5316\uff08\u5feb\u6377\u952e\uff1aShift+Option+Command+L\uff09<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509613\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h3>3.2 check style\u914d\u7f6e&#038;\u4f7f\u7528<\/h3>\n<p>check style\u7684\u914d\u7f6e\u548c\u4f7f\u7528\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>\u5728\u5f00\u53d1\u73af\u5883IDE\u4e2d\uff0c\u5f00\u53d1\u8005\u914d\u7f6e\u63d2\u4ef6\u540e\uff0c\u53ef\u89e6\u53d1\u4ee3\u7801\u6837\u5f0f\u89c4\u8303\u7684\u68c0\u67e5\uff0c\u6839\u636e\u63d0\u793a\u9879\u8fdb\u884c\u4ee3\u7801\u4fee\u6539\uff1b<\/li>\n<\/ol>\n<p>2.\u5728maven\u9879\u76ee\u4e2d\uff0c\u914d\u7f6echeckstyle\u63d2\u4ef6\uff0c\u53ef\u7528\u547d\u4ee4\u884c\u89e6\u53d1\u4ee3\u7801\u6837\u5f0f\u89c4\u8303\u7684\u68c0\u67e5\uff0c\u96c6\u6210\u5230CI (Continuous Integration)\u7684\u81ea\u52a8\u5316\u6d41\u6c34\u7ebf\u4e2d\uff1b<\/p>\n<h4>a. IDEA\u914d\u7f6eCheckStyle\u63d2\u4ef6<\/h4>\n<p>\u5728 IntelliJ IDEA\u4e0b\uff0c\u5b89\u88c5Plugin\uff0c\u8def\u5f84\uff1a<code>IntelliJ IDEA<\/code>\u2192<code>Preference<\/code>\u2192<code>Plugins<\/code>\uff0c\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509615\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p>\u4e0b\u8f7d\u914d\u7f6e\u6587\u4ef6<a href=\"https:\/\/link.segmentfault.com\/?enc=i%2B6uzCDALrH1Tu23whC2qg%3D%3D.oz1As7AvT3rcgOYe9XRwFCEP%2BdDelZd6Qg2r%2BoqYoy4oBmmHoiXNkW5flTz8zY7ccd4sBAV5xthu2KfvaFWVSCMC3WpZGm5h1jm8auz8RYc0pT2fV4Nn3N7hFYzLtEhi\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">checkstyle.xml<\/a>\uff0c\u914d\u7f6eCheckStyle-IDEA\u63d2\u4ef6\uff0c\u8def\u5f84\uff1a<code>IntelliJ IDEA<\/code>\u2192<code>Preference<\/code>\u2192<code>Tools<\/code>\u2192<code>Checkstyle<\/code>\uff0c\u589e\u52a0\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6\u5e76\u547d\u540d\uff0c\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509616\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h4>b. IDEA\u4f7f\u7528CheckStyle\u63d2\u4ef6<\/h4>\n<p>\u5b89\u88c5\u914d\u7f6eCheckStyle\u63d2\u4ef6\u540e\uff0c\u5de5\u5177\u7a97\u53e3\u589e\u52a0\u4e86CheckStyle Tab\uff0c\u5728CheckStyle\u7a97\u53e3\u8fdb\u884ccheck\uff0c\u53ef\u4ee5\u9009\u62e9\uff1a<\/p>\n<p>\u2022<code>Check Current File<\/code><\/p>\n<p>\u2022<code>Check Module<\/code><\/p>\n<p>\u2022<code>Check Project<\/code><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045509617\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h4>c. maven\u914d\u7f6eCheckStyle\u63d2\u4ef6<\/h4>\n<p>\u53c2\u8003Checkstyle maven\u63d2\u4ef6\u7684\u5b98\u65b9\u914d\u7f6e\u6848\u4f8b\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=UDDtJrSoSkNnw6tdRkxFPw%3D%3D.NZ3cX03TaGZ%2BBSnfSPhAXD5wCxVQQfquv8U6heoPd3buGWlKM8tSgtiAepXEm7czstU0abMi97bZsQwPLMXdgvjp8etAT6yuV2GwzoVcXAPhWUbNu0Pe6GPrNbHh1I7X\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u591a\u6a21\u5757\u9879\u76ee\u914d\u7f6e<\/a>\uff0c\u901a\u5e38\u6211\u4eec\u5728\u9879\u76ee\u4e2d\u65b0\u5efabuild-tools\u6a21\u5757\uff0c\u5c06checkstyle.xml\u7b49\u914d\u7f6e\u6587\u4ef6\u653e\u5728\u8fd9\u4e2a\u6a21\u5757\u7684resources\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre><code>project-name\n| -- pom.xml\n| -- build-tools\n| | -- pom.xml\n| | -- src\n| | | -- main\n| | | -- resources\n| | | -- checkstyle.xml\n| | | -- checkstyle-suppressions.xml\n| -- core\n| -- gui\n| -- other-module\n<\/code><\/pre>\n<p>build-tools\u6a21\u5757\u7684pom.xml\u4f7f\u7528IDEA\u81ea\u52a8\u751f\u6210\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7c7b\u4f3c\uff1a<\/p>\n<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;project&gt;\n    &lt;parent&gt;\n        &lt;artifactId&gt;project-name&lt;\/artifactId&gt;\n        &lt;groupId&gt;com.jd.project-name&lt;\/groupId&gt;\n        &lt;version&gt;1.0.0&lt;\/version&gt;\n    &lt;\/parent&gt;\n\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n    &lt;artifactId&gt;build-tools&lt;\/artifactId&gt;\n&lt;\/project&gt;\n<\/code><\/pre>\n<p>\u914d\u7f6e\u6587\u4ef6checkstyle.xml\u3001checkstyle-suppressions.xml\u53ef\u4ee5\u4ececoding\u4e2d\u4e0b\u8f7d<a href=\"https:\/\/link.segmentfault.com\/?enc=LyLm5F5m68JS2Htq5ciZVA%3D%3D.uTDdp6%2BzwD93dqRc8NbZ8jCKQfu9Aruq1v%2BcNCqDgRafVhtVk9vP8WrG5mJuoS8tlWoU18keMxY880nBLr8pucQqq%2BgcKEQyHWmsMcLqVjM%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">http:\/\/xingyun.jd.com\/codingRoot\/liuzhongwei18\/styleguide\/blo&#8230;<\/a>\u3002<\/p>\n<p>\u7236\u9879\u76ee\u7684pom.xml\u4e2d\uff0c\u589e\u52a0\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>&lt;project&gt;\n    ...\n    &lt;modules&gt;\n        ...\n        &lt;module&gt;build-tools&lt;\/module&gt;\n    &lt;\/modules&gt;\n\n    &lt;properties&gt;\n        ...\n        &lt;maven.checkstyle.version&gt;3.6.0&lt;\/maven.checkstyle.version&gt;\n    &lt;\/properties&gt;\n\n    &lt;build&gt;\n        &lt;pluginManagement&gt;\n            &lt;plugins&gt;\n                &lt;plugin&gt;\n                    &lt;!-- Approach followed here is roughly the same as mentioned here:\n                         https:\/\/maven.apache.org\/plugins\/maven-checkstyle-plugin\/examples\/multi-module-config.html\n                    --&gt;\n                    &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n                    &lt;artifactId&gt;maven-checkstyle-plugin&lt;\/artifactId&gt;\n                    &lt;version&gt;${maven.checkstyle.version}&lt;\/version&gt;\n                    &lt;configuration&gt;\n                        &lt;configLocation&gt;build-tools\/src\/main\/resources\/checkstyle.xml&lt;\/configLocation&gt;\n                        &lt;includeTestSourceDirectory&gt;true&lt;\/includeTestSourceDirectory&gt;\n                        &lt;outputFile&gt;checkstyle-report.xml&lt;\/outputFile&gt;\n                        &lt;consoleOutput&gt;false&lt;\/consoleOutput&gt;\n                        &lt;failOnViolation&gt;true&lt;\/failOnViolation&gt;\n                        &lt;excludes&gt;target\/**&lt;\/excludes&gt;\n                    &lt;\/configuration&gt;\n                    &lt;executions&gt;\n                        &lt;execution&gt;\n                            &lt;id&gt;checkstyle&lt;\/id&gt;\n                            &lt;phase&gt;validate&lt;\/phase&gt;\n                            &lt;goals&gt;\n                                &lt;goal&gt;check&lt;\/goal&gt;\n                            &lt;\/goals&gt;\n                        &lt;\/execution&gt;\n                    &lt;\/executions&gt;\n                &lt;\/plugin&gt;\n            &lt;\/plugins&gt;\n        &lt;\/pluginManagement&gt;\n        &lt;plugins&gt;\n            &lt;plugin&gt;\n                &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n                &lt;artifactId&gt;maven-checkstyle-plugin&lt;\/artifactId&gt;\n            &lt;\/plugin&gt;\n        &lt;\/plugins&gt;\n    &lt;\/build&gt;\n    &lt;reporting&gt;\n        &lt;plugins&gt;\n            &lt;plugin&gt;\n                &lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\n                &lt;artifactId&gt;maven-checkstyle-plugin&lt;\/artifactId&gt;\n                &lt;reportSets&gt;\n                    &lt;reportSet&gt;\n                        &lt;reports&gt;\n                            &lt;report&gt;checkstyle&lt;\/report&gt;\n                        &lt;\/reports&gt;\n                    &lt;\/reportSet&gt;\n                &lt;\/reportSets&gt;\n            &lt;\/plugin&gt;\n        &lt;\/plugins&gt;\n    &lt;\/reporting&gt;\n\n&lt;\/project&gt;\n<\/code><\/pre>\n<p>maven-checkstyle-plugin\u7684\u914d\u7f6e&lt;configuration&gt;\u53c2\u6570\u5177\u4f53\u53ef\u53c2\u89c1<a href=\"https:\/\/link.segmentfault.com\/?enc=bOWanI0IUqyU325e%2FQqidA%3D%3D.sNp75M1Q5B7ixYBgnnN6gHDSEhRXRrE0BB0qj0pXNHkmw0lxGmi2waUEqpDuLCael5pN4ZfCPQP6%2FgA4UsjW3lPfCJfzErkV0wApKTa76i8%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">checkstyle:check<\/a>\u7684\u53c2\u6570\u8bf4\u660e\u3002<\/p>\n<p>\u8fd9\u91cc\u5bf9\u51e0\u9879\u914d\u7f6e\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n<p>\u2022plugins&gt;plugin&gt;executions&gt;execution<\/p>\n<p>\u25e6id\u53ef\u4ee5\u81ea\u884c\u51b3\u5b9a\uff0c\u8fd9\u91cc\u9009\u62e9&#8221;checkstyle&#8221;\uff1b<\/p>\n<p>\u25e6phase\u662f\u7ed1\u5b9a\u5230maven lifecycle\u7684\u54ea\u4e2a\u6267\u884c\u9636\u6bb5\uff0c\u8fd9\u91cc\u7ed1\u5b9a\u5230&#8221;<a href=\"https:\/\/link.segmentfault.com\/?enc=6BrEC%2BAhEfVltIlheowZ8g%3D%3D.Z1t169sB0nE4hgqdj33uAG%2BIg6vDX63U7pce%2BXI6VF5sZD%2FoQqQVPxU6TBLlvv6dZVL9Zl0QdXH8XwxZUqpCSKNgn9l1ZdaxJZDvw7dfbS1u5GQWzGM32LifptOtsabv3AQp9QBNeOrky0Oz92vSNWJGjkpsRKJlNkeDrJcqCqY%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">validate<\/a>&#8220;\u4e0a\uff0c\u5373\u6267\u884cmaven validate\u7684\u65f6\u5019\u4f1a\u6267\u884c\u8be5plugin\u4efb\u52a1\uff1b\u9009\u62e9validate\u9636\u6bb5\u53ef\u4ee5\u4fdd\u969ccheckstyle:check\u5728\u4ee3\u7801\u7f16\u8bd1\u4e4b\u524d\u6267\u884c\uff0c\u5982\u679ccheckstyle\u68c0\u67e5\u51fa\u8fdd\u53cd\u6837\u5f0f\u89c4\u8303\u7684\u95ee\u9898\uff0c\u5728\u4ee3\u7801\u7f16\u8bd1\u4e4b\u524d\u5c31\u4f1a\u62a5\u544a\u51fa\u6765\uff1b<\/p>\n<p>\u25e6goals&gt;goal\u662f\u53ea\u7ed1\u5b9a\u6267\u884cplugin\u7684\u54ea\u4e2a\u4efb\u52a1\uff0c\u8fd9\u91cc\u7ed1\u5b9a\u7684\u662f&#8221;check&#8221;\uff1b<\/p>\n<p>\u2022plugins&gt;plugin&gt;configuration&gt;failOnViolation<\/p>\n<p>\u25e6\u68c0\u67e5\u5230\u8fdd\u53cd\u6837\u5f0f\u89c4\u8303\u7684\u95ee\u9898\uff0c\u6253\u5370\u51fa\u6765\uff0c\u6253\u5370\u7684\u95ee\u9898\u7ea7\u522b\u6839\u636e<a href=\"https:\/\/link.segmentfault.com\/?enc=OnLRk%2FbCu2k9ZBkc4Qph%2FA%3D%3D.cDcPP1EFq1upcPsueKA7alZEOlpN2vicBOU7Pf0As9Gzx9B5V0CzAIsdoLQII4zkLKM8Nl%2FT6NyyyBRUil6%2BXoVM3YC7Ifp5mwCzm6Nv7%2BUhO2FII7VIKgFDjlWkIbXK\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">checkstyle.xml<\/a>\u4e2d\u914d\u7f6e\u7684severity\u786e\u5b9a\uff1b<\/p>\n<p>\u25e6\u5c06severity\u7ea7\u522b\u914d\u7f6e\u4e3aerror\uff0c\u5e76\u5c06failOnViolation\u8bbe\u4e3atrue\uff0c\u68c0\u67e5\u5230\u8fdd\u53cd\u6837\u5f0f\u89c4\u8303\u7684\u95ee\u9898\u65f6\uff0c\u4f1a\u505c\u6b62maven\u547d\u4ee4\u7ee7\u7eed\u6267\u884c\uff1b<\/p>\n<p>\u6ce8\u610f\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=ngDmnr3jNhKLFgXriRLEsw%3D%3D.fmxbjJRr%2FYBMj7S%2B30duhG9GJW%2BxJFw9JH4Nkgqc9Z%2B8jnjY%2BJWesQDRcDylb2o0kDx%2BaR0XXpY%2FczE07WB0vchqHyVH1%2BnqHQp7bfs72R7iTZfibLB8cIqcGsU9QWdk\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">failOnViolation<\/a>\u4e0e<a href=\"https:\/\/link.segmentfault.com\/?enc=ix0NvSK8mWCLQSG5DvhECQ%3D%3D.QfqBb9mG97nu6FrEbAFQPQtQvXHrXYKWuQQ0vbW6DKgba5NfoqeuXkW6oolPSc6va6FxWFMY%2BHnD6uy5r3pWTKhV6bd9lOCLF0Htno1cyVKYDb5HLTPjd3f2ynHwxA4A\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">failOnError<\/a>\u914d\u7f6e\u9879\u7684\u533a\u522b\uff0cfailOnError\u5728\u68c0\u67e5\u5230\u95ee\u9898\u65f6\u7acb\u5373\u505c\u6b62\u6267\u884c\uff0cfailOnViolation\u5728\u68c0\u67e5\u5230\u95ee\u9898\u65f6\u8f93\u51fa\u68c0\u67e5\u65e5\u5fd7\u518d\u505c\u6b62\u6267\u884c\u3002<\/p>\n<p>\u6309\u7167\u4e0a\u8ff0\u914d\u7f6e\uff0c\u53ef\u8fbe\u5230\u5728mvn\u7f16\u8bd1\u4ee3\u7801\u524d\u5f3a\u5236\u68c0\u67e5\u4ee3\u7801\u6837\u5f0f\u89c4\u8303\uff0c\u53d1\u73b0\u8fdd\u53cd\u89c4\u8303\u7684\u95ee\u9898\uff0c\u4e0d\u4f1a\u7ee7\u7eedjava\u7684\u7f16\u8bd1\u3001\u6253\u5305\u3002<\/p>\n<h4>d. maven\u4f7f\u7528CheckStyle\u63d2\u4ef6<\/h4>\n<p>\u8fd0\u884cmvn package\u5373\u53ef\u6b63\u5e38\u6253\u5305\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u5355\u72ec\u6267\u884c\u547d\u4ee4\uff1a<\/p>\n<pre><code>mvn checkstyle:check\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a\u4e3a\u4e86\u5b9e\u73b0\u81ea\u52a8\u5316\u4ee3\u7801\u6837\u5f0f\u89c4\u8303\u68c0\u67e5\uff0c\u53ef\u4ee5\u4e3a\u9879\u76ee\u914d\u7f6e\u884c\u4e91\u6d41\u6c34\u7ebf\u4efb\u52a1\uff0c\u8bbe\u7f6e\u4ee3\u7801\u8bc4\u5ba1\u7684<a href=\"https:\/\/link.segmentfault.com\/?enc=aR%2FNO8dLeXKWM0XQARalzw%3D%3D.6KVluV%2FWTFeWxh%2FMXhgkkQfA82%2B4PSPcwD1XcoHaGcPe6EHb85ibnrFEooPD52aO60JHuX9aJPsMEpg9tIuZ%2FA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u81ea\u52a8\u5316\u68c0\u67e5<\/a>\uff1a\u6307\u5b9a\u6d41\u6c34\u7ebf\u505a\u4e3a\u5361\u70b9\uff0c\u6307\u5b9a\u4e3a\u5361\u70b9\u7684\u6d41\u6c34\u7ebf\u9700\u8fd0\u884c\u6210\u529f\u540eMR\u624d\u5141\u8bb8\u5408\u5e76\u3002<\/p>\n<\/p>\n<h2><strong>\u56db\u3001\u7ed3\u8bed\uff1a\u4ee3\u7801\u89c4\u8303-\u56e2\u961f\u534f\u4f5c\u7684\u6865\u6881<\/strong><\/h2>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u603b\u7ed3\u4e0bJava\u6837\u5f0f\u89c4\u8303\u5bf9\u4e8e\u56e2\u961f\u534f\u4f5c\u7684\u91cd\u8981\u6027\uff0c\u9f13\u52b1\u6bcf\u4f4d\u5f00\u53d1\u8005\u5c06\u8fd9\u4e9b\u89c4\u8303\u5185\u5316\u4e3a\u81ea\u5df1\u7684\u7f16\u7801\u4e60\u60ef\u3002\u56e0\u4e3a\u4ee3\u7801\u89c4\u8303\u4e0d\u4ec5\u662f\u4e2a\u4eba\u6280\u827a\u7684\u4f53\u73b0\uff0c\u66f4\u662f\u56e2\u961f\u534f\u4f5c\u548c\u9879\u76ee\u6210\u529f\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u901a\u8fc7\u9605\u8bfb\u672c\u6587\uff0c\u4f60\u5c06\u4e0d\u4ec5\u4e86\u89e3\u5230Java\u6837\u5f0f\u89c4\u8303\u7684\u91cd\u8981\u6027\uff0c\u8fd8\u5c06\u638c\u63e1\u5982\u4f55\u5c06\u8fd9\u4e9b\u89c4\u8303\u5e94\u7528\u5230\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u8ba9\u4f60\u7684\u4ee3\u7801\u53d8\u5f97\u66f4\u52a0\u4f18\u96c5\u548c\u5f3a\u5927\u3002\u8ba9\u6211\u4eec\u4e00\u8d77\u8ffd\u6c42\u7f16\u7801\u7684\u827a\u672f\uff0c\u7528\u89c4\u8303\u7684\u4ee3\u7801\u70b9\u4eae\u7f16\u7a0b\u7684\u4e16\u754c\u3002<\/p>\n<\/p>\n<h2>\u53c2\u8003<\/h2>\n<p>\u2022<a href=\"https:\/\/link.segmentfault.com\/?enc=S6%2FSk0BVMOhau6zUII9tng%3D%3D.TGh2IGFpsdT8mLiQXS3OZ%2FBG8i4WjyG1JfJAoeSbz2hgIiyNRatbrPA96DL5JjIKLFFNBe8jGHeiH1y3QzyfYw%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u4eac\u4e1cJAVA\u4ee3\u7801\u89c4\u8303-V1.0.pdf<\/a><\/p>\n<p>\u2022JD\u7f16\u7801\u89c4\u8303\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=JxEAxUkxPedvDH160qeLSw%3D%3D.gx%2B0%2FVPUJiroTD%2Fptt9GOl3ikZ1n5VFvi6KX3gxGlahlKbiV7gmQSTiuoFXxyFSBjc0xdLVv6yyLySrQRs9eli%2F5lNcECVnmWjaJu91h7v8CsaXMvORai944SvFxWHQB\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/doc.jd.com\/base\/eos-doc\/system-rule\/JD%E7%BC%96%E7%A0&#8230;<\/a><\/p>\n<p>\u2022Jetbrains Java code style: <a href=\"https:\/\/link.segmentfault.com\/?enc=aMPfxcfefRJ6V08f0ZxY2w%3D%3D.2Y%2Bapuqay3eIeNcZm1nQfRQxb8j9Gq0XZDOBpjKkRufmg%2FDCg5Wug2d94l9S6t%2F054NLu0%2FtGZAsUwK5qky%2FIw%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/www.jetbrains.com\/help\/idea\/code-style-java.html<\/a><\/p>\n<p>\u2022checkstyle\u5b98\u7f51\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=O3oH1BJwelayhF%2FqTtM8gg%3D%3D.AWNygLcGKOxbOpNG6WF403%2B61NRA8I5wWIlsTR9S6vW0tqiBJ51Jq%2FH%2FULzf9vPe\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/checkstyle.org\/index.html<\/a><\/p>\n<p>\u2022checkstyle\u53d1\u5e03\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=s2%2FhXmpJRUViXMfHSWxc8Q%3D%3D.CPpx2bndS1UY%2BOivdotOMIYPYc2MPx1evGB%2FrnWZ9hnR9qnuKrcR3Z0etOEpgZyYRhDm%2F7T4B8U50Qjo4fWsHg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/checkstyle\/checkstyle\/releases\/<\/a><\/p>\n<p>\u2022Apache Maven Checkstyle Plugin: <a href=\"https:\/\/link.segmentfault.com\/?enc=Ri9bYFF9VieGWBR7ITSjzw%3D%3D.nCDFgvASP48QqyJwnWDJ0I3azCgzUUkQWGxVexBlbwKL6D0wLmvXn1GkbMAUqI1NblD0DRs8dNVeBoFyZiXDcJzdZnLTfIKypxa5%2BMJxVn4%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">https:\/\/maven.apache.org\/plugins\/maven-checkstyle-plugin\/usag&#8230;<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045509608\">https:\/\/segmentfault.com\/a\/1190000045509608<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u96f6\u552e \u5218\u4ef2\u4f1f \u5728\u8f6f\u4ef6\u5f00\u53d1\u7684\u4e16\u754c\u91cc\uff0c\u4ee3\u7801\u4e0d\u4ec5\u662f\u7a0b\u5e8f\u7684\u57fa\u77f3\uff0c\u66f4\u662f\u7a0b\u5e8f\u5458\u4ea4\u6d41\u7684\u901a\u7528\u8bed\u8a00\u3002\u800cJava\uff0c\u4f5c\u4e3a\u4e00 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020422","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020422"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020422\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}