Java 文檔一直是一個大問題。java
不少項目不寫文檔,即便寫文檔,對於開發人員來講也是很是痛苦的。git
不寫文檔的缺點自不用多少,手動寫文檔的缺點也顯而易見:github
java 的文檔有幾類:api
就算是咱們 java 開發者,也很討厭看 jdk 的文檔。看着不美觀,也很累。markdown
可是缺點也是有的。開發人員要寫 jdk 原來的註釋+註解。註解太多,致使寫起來也很痛苦,大部分開發者後來仍是選擇了放棄。maven
那麼問題來了?咱們怎麼辦才能儘量的讓開發人員,和文檔閱讀人員都樂於接受呢?工具
jdk 自帶的 doc 就是基於 maven 插件的,本項目也是。學習
區別以下:測試
爲 java 項目生成項目文檔。ui
基於原生的 java 註釋,儘量的生成簡介的文檔。用戶能夠自定義本身的模板,生成本身須要的文檔。
jdk1.8+
maven 3.x+
使用 maven 引入當前 idoc 插件。
<build> <plugins> <plugin> <groupId>com.github.houbb</groupId> <artifactId>idoc-core</artifactId> <version>0.1.0</version> </plugin> </plugins> </build>
爲了演示文檔,咱們建立了一個 Address 對象。
package com.github.houbb.idoc.test.model; /** * 地址 * @author binbin.hou * @since 0.0.1 */ public class Address { /** * 城市 */ private String country; /** * 街道 */ private String street; public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } }
mvn com.github.houbb:idoc-core:0.0.2:idoc
[INFO] ------------------------------------ Start generate doc [INFO] 共計 【1】 個文件待處理,請耐心等待。進度以下: ==================================================================================================== 100% [INFO] Generator doc with docGenerator: com.github.houbb.idoc.core.api.generator.ConsoleDocGenerator [INFO] ------------------------------------ 文檔信息以下: [類名] com.github.houbb.idoc.test.model.Address [類信息] {"comment":"地址","docAnnotationList":[],"docFieldList":[{"comment":"城市","name":"country","type":"java.lang.String"},{"comment":"街道","name":"street","type":"java.lang.String"}],"docMethodList":[{"docMethodParameterList":[],"docMethodReturn":{"fullName":"java.lang.String","name":"String","packageName":"java.lang"},"docTagList":[],"exceptionList":[],"modifiers":["public"],"name":"getCountry","seeList":[],"signature":"getCountry()"},{"docMethodParameterList":[{"docAnnotationList":[],"name":"country","type":"java.lang.String"}],"docMethodReturn":{},"docTagList":[],"exceptionList":[],"modifiers":["public"],"name":"setCountry","seeList":[],"signature":"setCountry(country)"},{"docMethodParameterList":[],"docMethodReturn":{"fullName":"java.lang.String","name":"String","packageName":"java.lang"},"docTagList":[],"exceptionList":[],"modifiers":["public"],"name":"getStreet","seeList":[],"signature":"getStreet()"},{"docMethodParameterList":[{"docAnnotationList":[],"name":"street","type":"java.lang.String"}],"docMethodReturn":{},"docTagList":[],"exceptionList":[],"modifiers":["public"],"name":"setStreet","seeList":[],"signature":"setStreet(street)"}],"docTagList":[{"lineNum":5,"name":"author","parameters":["binbin.hou"],"value":"binbin.hou"},{"lineNum":6,"name":"since","parameters":["0.0.1"],"value":"0.0.1"}],"fullName":"com.github.houbb.idoc.test.model.Address","modifiers":["public"],"name":"Address","packageName":"com.github.houbb.idoc.test.model"} [INFO] ------------------------------------ Finish generate doc
效果參見 idoc-test-所有文檔.md