maven项目发布到自己搭建的maven私服

最近做项目,需要把项目编译成jar发布到maven私服上,方便别的应用加载使用。查了些资料,终于搞定,mark一下

步骤一、编译服务器或自己的开发电脑,配置settings.xml。

1、centos找到/etc/maven下的settings.xml。window电脑找到maven的安装目录下conf下的settings.xml。

2、找到servers节点,配置下面一段脚本

<servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     | 
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are 
     |       used together.
     |
    -->
    <server>
      <id>nexus-xxx</id>
      <username>admin</username>
      <password>xxxxxx</password>
    </server>
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

步骤二、配置项目pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.xxx.test</groupId>
    <artifactId>model-jar</artifactId>
    <version>1.0</version>
    
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <!--下面两个配置不会将源包上传-->
        <!--<maven.javadoc.skip>true</maven.javadoc.skip>
        <maven.source.skip>true</maven.source.skip>-->
    </properties>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <distributionManagement>
        <!--稳定版本的仓库地址,必须是允许上传的私服地址-->
        <repository>
            <!--id和maven setting文件server id保持一致则不需要配置用户名密码,否则需要在pom中配置用户名密码-->
            <id>nexus-xxx</id>
            <url>http://maven.xxx.com/repository/xxx/</url>
        </repository>
    </distributionManagement>
</project>

步骤三、编译

使用下面脚本编译

mvn clean package deploy 

发布到maven服务器上版本如下
在这里插入图片描述
另外,该项目通过jenkins编译,需要传参给pom文件修改版本号,jenkins界面配置参数化编译,这里不再赘述。

1、编译命令,传入参数

mvn clean package deploy -Dver=${VERSION_CODE}

2、pom文件接收参数

在上面pom文件中修改下面两处

    <groupId>com.xxx.test</groupId>
    <artifactId>model-jar</artifactId>
    <!--1 在上面的文件中修改-->
    <version>${ver}</version>
    
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <!--下面两个配置不会将源包上传-->
        <!--<maven.javadoc.skip>true</maven.javadoc.skip>
        <maven.source.skip>true</maven.source.skip>-->
        <!--2 在上面的文件中添加下面一行-->
        <ver>0.1</ver>
        <maven-jar-plugin.version>3.8.1</maven-jar-plugin.version>

    </properties>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值