上传jar及源码到maven仓库

前提

配置 maven settings.xml


15595522-ca17673a93ed453f.png
settings.xml
    <server>
      <id>maven-releases</id>
      <username>admin</username>
      <password>padmin</password>
    </server>

方式一 通过命令直接上传

比如

 mvn deploy:deploy-file -DgroupId=**.** -DartifactId=** -Dversion=0.0.7 -Dpackaging=jar -Dfile=**.jar -Durl=http://ip:port/**/ -DrepositoryId=maven-releases

-DgroupId :jar所属组
-DartifactId:jar所属id
-Dfile:jar包名(如果在jar所在目录执行命令,则不需要带路径)
-Durl:maven服务器的仓库地址(如:http://ip:port/repository/maven-releases/

该方式只能上传jar,无法上传源码
可能与命令使用不当有关

方式二 通过IDEA上传

配置项目的 pom.xml

    <distributionManagement>
        <repository>
            <!-- 这里的id需要和settings.xml中的server的id一致 -->
            <id>maven-releases</id>
            <name>maven-releases</name>
            <url>http://ip:port/**</url>
        </repository>
    </distributionManagement>
 <build>
        <plugins>
            <!-- 要将源码放上去,需要加入这个插件 -->
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
15595522-5d3cb93a49cc9f07.png
配置pom.xml

执行命令进行上传

mvn deploy或点击IDEA的maven插件的Lifecycle>deploy

15595522-c782d0b747d9c34c.png

方式一与二的优缺

优点
方式一:可以上传任何的jar文件
方式二:可以上传jar与源码文件
缺点
方式一:上传的jar无源码关联
方式二:需要持有源码工程

转载于:https://www.jianshu.com/p/6aecffd46481

猜你喜欢

转载自blog.csdn.net/weixin_34352005/article/details/91152760