在创建Java库后,上传到远程仓库时,最好带上源码包方便使用的人理解,不然功能只完成了一半,东西给别人用了,但是别人不知道怎么用。
1 添加配置
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- explicitly define maven-deploy-plugin after other to force exec order -->
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals><goal>deploy</goal></goals>
</execution>
</executions>
</plugin>
2 mvn clean install或者mvn clean deploy
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ starterdemo ---
[INFO] Installing D:\code\fordemo\starterdemo\target\starterdemo-0.0.1-SNAPSHOT.jar to C:\Users\aihe\.m2\repository\me\aihe\starterdemo\0.0.1-SNAPSHOT\starterdemo-0.0.
1-SNAPSHOT.jar
[INFO] Installing D:\code\fordemo\starterdemo\pom.xml to C:\Users\aihe\.m2\repository\me\aihe\starterdemo\0.0.1-SNAPSHOT\starterdemo-0.0.1-SNAPSHOT.pom
[INFO] Installing D:\code\fordemo\starterdemo\target\starterdemo-0.0.1-SNAPSHOT-sources.jar to C:\Users\aihe\.m2\repository\me\aihe\starterdemo\0.0.1-SNAPSHOT\starterd
emo-0.0.1-SNAPSHOT-sources.jar
[INFO] ------------------------------------------------------------------------
3 查看内容

image.png