上传组件jar和源码到maven仓库

操作

在父级pom中添加

<distributionManagement>
        <snapshotRepository>
            <id>sge</id>//这个位置的id需要和maven的settings.xml文件中想匹配
            <name>gitlab-runner</name>//这个name是maven上传jar包到仓库的用户名
            <url>http://180.2.35.50:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>sge-release</id>
            <name>gitlab-runner</name>
            <url>http://180.2.35.50:8081/repository/maven-releases/</url>
        </repository>
    </distributionManagement>

<pluginManagement>
   <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <version>3.0.1</version>
          <configuration>
             <attach>true</attach>
          </configuration>
             <executions>
                 <execution>
                     <phase>compile</phase>
                         <goals>
                            <goal>jar</goal>
                         </goals>
                 </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>

在子模块中添加

<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
</plugin>

maven的settings.xml中配置server的信息

<servers>
    <server>
      <id>sge</id>
      <username>gitlab-runner</username>//这里的用户名和密码是登录maven仓库(Nexus)的,具有上传jar包的权限。
      <password>gitlab-runner</password>
    </server>
  </servers>

验证

使用IDEA或者命令行执行 mvn deploy

打开远程仓库,查看你项目所在的snapshots或者release目录下,找到那个jar包,
看看是否有个xxxx-snapshots-sources.jar 的包。如果有就成功了。

如果在执行部署的时候失败了,那多半是因为你的账户名不对。

参考:https://maven.apache.org/pom.html#Repositories
https://maven.apache.org/settings.html

posted @ 2021-01-12 19:08  头上有多云  阅读(304)  评论(0编辑  收藏  举报