maven分模块设计与私服

一、maven分模块设计

1、好处
  • 增强代码的复用性
  • 便于分工
  • 对 maven 项目来讲,一些通用的依赖、插件,可以抽取到父模块,简化配置
2、注意事项
<!--    父工程pom.xml中配置打包方式时选择pom方式,该模块不写java代码,仅进行项目管理配置-->
    <packaging>pom</packaging>
3、聚合

​ 在父模块pom.xml中使用module标签统一管理子模块叫做聚合。

​ 好处是通过父模块能够快速构建(清理、编译、打包)多个子模块。

4、继承

​ 描述的是两个工程间的关系,

​ 作用是简化依赖配置、统一管理依赖,

​ 实现:在子模块pom.xml中使用标签指定要继承的父模块

5、版本锁定
1、在父模块锁定版本
    <properties>
        <!--     自定义属性     -->
        <jjwt.version>0.9.1</jjwt.version>
    </properties>
<!--
    在父模块中的pom.xml中使用 dependencyManagement 标签定义要锁定版本的依赖坐标
    在子模块中定义依赖时,如果不指定就使用父模块的版本,如果指定了就用子模块中的
-->
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <!--     引用属性     -->
                <version>${jjwt.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

2、在子模块中使用依赖
        <!--
            在父模块中的pom.xml中使用 dependencyManagement 标签定义要锁定版本的依赖坐标
            在子模块中定义依赖时,如果不指定就使用父模块的版本,如果指定了就用子模块中的
        -->
       <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
        </dependency>

            <!--打包插件,打包时报错找不到启动类时添加-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.yourcompany.yourproject.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

二、私服Nexus

1、下载

官网下载

2、从私服下载jar
    <!--在pom.xml中配置从私服下载jar包的仓库组地址,注意:nexus开要开启允许匿名访问-->
    <repositories>
        <repository>
            <!--多个repository时,id唯一就行-->
            <id>nexus</id>
            <!--仓库组的url-->
            <url>http://http://192.168.69.60/:8081/repository/maven-public/</url>
        </repository>
    </repositories>
3、上传jar到私服
    <!--在pom.xml中配置上传jar包到私服的地址-->
    <distributionManagement>
        <!-- release版本的发布地址 -->
        <repository><!--此处的id要和server中的id一致,表示使用这组密码-->
            <id>maven-nexus</id>
            <url>http://192.168.69.60:8081/repository/maven-releases/</url>
        </repository>

        <!-- snapshot版本的发布地址 -->
        <snapshotRepository>
            <id>maven-nexus</id><!--此处的id要和server中的id一致,表示使用这组密码-->
            <url>http://192.168.69.60:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
 <!--在maven的settings.xml中的servers中配置 私服的访问用户名/密码-->
      <server>
          <id>maven-nexus</id>
          <username>admin</username>
          <password>123456</password>
      </server>

最后,在IDEA中双击 deploy 发布项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值