创建Maven源代码和Javadoc工件
許多人都知道Maven源代碼和Javadoc工件,但是不知道為什么要創建它們。 我肯定在這個陣營中–我可以理解為什么人們想要此信息,但是由于要手動導航Maven存儲庫,因此獲取信息似乎相對效率較低。
然后我被線索棒擊中。
這些工件由IDE而非人員使用。 如果您使用的是Maven依賴項,那么IDE足夠聰明,可以知道如何查找這些工件。 當您單步調試器中的代碼時,將使用源工件-您不再需要將源代碼顯式綁定到IDE中的庫。 javadoc工件用于編輯器中的自動完成和上下文相關幫助。
這些都不是必需的-多年以來我一直很高興使用'vi'-但是當您大多數都知道自己需要什么但不確定細節時,它肯定會提高您的生產率。
源工件
源工件最容易創建。 添加一個將作為標準構建的一部分自動運行的插件,您已完成。 構建花費的時間稍長一些,但您只需要創建幾個目錄的歸檔文件就不必擔心了。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><build><plugins><!-- create source jar --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>2.1.1</version><executions><execution><id>attach-sources</id><phase>verify</phase><goals><!-- produce source artifact for project main sources --><goal>jar-no-fork</goal><!-- produce test source artifact for project test sources --><goal>test-jar-no-fork</goal></goals></execution></executions></plugin></plugins></build> </project>Javadoc工件
Javadoc工件要復雜一些,因為您可能希望同時創建一個對人類友好的網站。 根據我的經驗,最大的問題是外部類是不透明的,因為它花費了大量的精力來創建必要的鏈接。 現在,maven插件會為我們解決這個問題!
構建該工件需要花費大量時間,因此您可能不想每次都這樣做。 有兩種方法–明確指定Maven目標或將其綁定到自定義配置文件,例如'javadoc'。 以下配置使用自定義配置文件。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><profiles><!-- create javadoc --><profile><id>javadoc</id><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><configuration><detectLinks /><includeDependencySources>true</includeDependencySources><dependencySourceIncludes><dependencySourceInclude>com.invariantproperties.project.student:*</dependencySourceInclude></dependencySourceIncludes><!-- heavily used dependencies --><links><link>http://docs.oracle.com/javase/7/docs/api/</link><link>http://docs.oracle.com/javaee/6/api</link><link>http://docs.spring.io/spring/docs/current/javadoc-api/</link><link>http://docs.spring.io/spring-data/commons/docs/1.6.2.RELEASE/api/</link><link>http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/api/</link><link>http://docs.spring.io/spring-data/data-jpa/docs/1.4.3.RELEASE/api/</link><link>https://jersey.java.net/apidocs/1.17/jersey/</link><link>http://hamcrest.org/JavaHamcrest/javadoc/1.3/</link><link>http://eclipse.org/aspectj/doc/released/runtime-api/</link><link>http://eclipse.org/aspectj/doc/released/weaver-api</link><link>http://tapestry.apache.org/5.3.7/apidocs/</link></links></configuration><executions><execution><id>aggregate</id><!-- <phase>site</phase> --><phase>package</phase><goals><goal>aggregate</goal><goal>jar</goal></goals></execution></executions></plugin></plugins></build><reporting><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><configuration><!-- Default configuration for all reports --></configuration><reportSets><reportSet><id>non-aggregate</id><configuration><!-- Specific configuration for the non aggregate report --></configuration><reports><report>javadoc</report></reports></reportSet><reportSet><id>aggregate</id><configuration><!-- Specific configuration for the aggregate report --></configuration><reports><report>aggregate</report></reports></reportSet></reportSets></plugin></plugins></reporting></profile></profiles> </project>包信息.java
最后,每個軟件包都應該具有package-info.java文件。 這將替換舊的package-info.html文件,但由于它允許使用類注釋,因此是一個改進。 (由于它是無效的類名,因此不會被編譯。)
我發現包括指向資源的鏈接非常有幫助,這些鏈接可以幫助我理解類的外觀。 例如,“學生”項目中的元數據包包含指向我的博客文章,我認為有用的其他博客文章甚至適當的Oracle教程的鏈接。 在公司中,這些可能是指向Wiki頁面的鏈接。
/** * Classes that support JPA Criteria Queries for persistent entities.* * @see <a href="http://invariantproperties.com/2013/12/19/project-student-persistence-with-spring-data/">Project Student: Persistence with Spring Data</a>* @see <a href="http://invariantproperties.com/2013/12/29/project-student-jpa-criteria-queries/">Project Student: JPA Criteria Queries</a>* @see <a href="http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-four-jpa-criteria-queries/">Spring Data JPA Tutorial Part Four: JPA Criteria Queries</a> [www.petrikainulainen.net]* @see <a href="http://docs.oracle.com/javaee/6/tutorial/doc/gjitv.html">JEE Tutorial</a> * * @author Bear Giles <bgiles@coyotesong.com>*/ package com.invariantproperties.project.student.metamodel;源代碼
- 源代碼位于https://github.com/beargiles/project-student [github]和http://beargiles.github.io/project-student/ [github頁面]。
翻譯自: https://www.javacodegeeks.com/2014/02/creating-maven-source-and-javadoc-artifacts.html
總結
以上是生活随笔為你收集整理的创建Maven源代码和Javadoc工件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果11双卡信号比单卡弱怎么解决
- 下一篇: JavaFX自定义控件– Nest Th