`
weiguo21
  • 浏览: 17285 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

maven项目打包发布到私有仓库

 
阅读更多

在项目开发中通常会引用其他的jar,怎样把自己的项目做为一个jar包的形式发布到私服仓库中,主要有以下三个步骤

(怎样配置maven私服仓库,就不再这里说明了,可以参考以前的文章)1.在maven的setting.xml中配置用户名和密码:

<servers>
    <server>
        <username>admin</username>
        <password>admin123</password>
        <id>nexus-release</id>
    </server>
    <server>
        <username>admin</username>
        <password>admin</password>
        <id>nexus-snapshots</id>
    </server>
</servers>
注意:要在nexus中打开相应的snapshots和releases仓库中的允许发布的开关

2.在发布的项目中配置pom.xml

如果有parent只需在parent中的pom.xml中配置,没有则在本项目的pom.xml配置即可
<distributionManagement>
<repository>
<id>nexus-release</id>
<url>http://192.168.0.247/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://192.168.0.247/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement> <!--上传source.jar 非必须 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

3.在依赖的项目添加依赖(注意版本是snapshot还是release)

snapshot版本还是release版本取决于发布项目中的配置

例如

<properties>
<!-- 依赖的版本定义 -->
<mes.version>0.0.1-RELEASE</mes.version>
</properties>
<dependencies>
<!-- 系统消息服务 -->
<dependency>
<groupId>com.longda.message</groupId>
<artifactId>mes-core</artifactId>
<version>${mes.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

</dependencies>

相应的待发布项目中配置如下

<modelVersion>4.0.0</modelVersion>
<groupId>com.longda.message</groupId>
<artifactId>mes-core</artifactId>
<version>0.0.1-RELEASE</version>
<packaging>jar</packaging>
<name>mes-core</name>
<url>http://maven.apache.org</url>
<properties>
<project.release.version>0.1-RELEASE</project.release.version>

</dependencies>

注意:简而言之就是两边的版本一定要对应上,至于是发布snapshot版本还是release版本需要在第二步中指定

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics