通常我們將項目打包的時候使用的命令如下:
mvn clean install
或
./mvnw clean install
這樣我們打包通常是隻打包了一個jar包,打開源碼的時候裏面的註釋都丟失了,那如何將註釋也一起打進來呢?那我們就要引入一個生成源碼資源包的插件:
<!--配置生成源碼包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
將該項目引入pom文件中,然後再執行如上命令,倉庫中就會出現兩個jar:
_remote.repositories
sgrain-spring-boot-common-service-2.1.1.RELEASE-sources.jar
sgrain-spring-boot-common-service-2.1.1.RELEASE.jar
sgrain-spring-boot-common-service-2.1.1.RELEASE.pom
如上會多一個sources.jar包,這個包就是源碼包,包含我們的註解,在查看註解的時候就可以從中央倉庫download註解包了。
GitHub地址:https://github.com/mingyang66/spring-parent/tree/master/doc/maven