maven关键知识点总结

上传源码包

用下面这个插件,可以上传源码到仓库中

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

命令总结

#第一步, 执行该命令,可以在本地仓库 安装 jar, 这样 本地应用就可以直接读取到最新的jar包

mvn clean install -U

#第二步,上传到远程仓库, 如果本地打了源码包,那么会将源码包上传到仓库
mvn deploy

问题总结

有时候,拉取最新的jar包后,查看源码 发现 不是最新的。

可以反编译一下 .class ,确认是不是最新的。一般都是最新的,为什么 查看源码缺拿不到最新的呢?

可能原因是 没有上传 最新的源码包 到远程仓库,导致 本地 idea 依然用的旧的源码文件

idea配置maven

快速迭代的过程,版本一般使用快照版本。可以看下idea的设置:

多模块管理

通常一个项目是由多模块进行管理。父pom 用特殊标签 管理模块。现在有 A/B/C三个模块,

    <modules>
        <module>A</module>
        <module>B</module>
        <module>c</module>
    </modules>
    <packaging>pom</packaging>

A/B/C三个模块的父pom都是这个pom。

   <parent>
        <artifactId>le-mav/artifactId>
        <groupId>com.wxj</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath/>
    </parent>

一种场景是, 如果父pom 需要显示添加 A模块作为认的依赖包进行传递。打包时 会报错:

[ERROR] [ERROR] The projects in the reactor contain a cyclic reference: Edge between 

出现了循环引用。原因是父pom 强制传递了A模块,A模块自己怎么依赖自己?!

解决方法

第一种:

A 模块 不用 父pom作为自己的 父pom。 把父pom 移除即可。

第二种:

A模块 不用 父pom 进行管理。 A模块的父pom不用移除。也可以解决

依赖管理

maven的两个标签可以管理依赖传递:

属性传递:

<properties>
    <java.version>1.8</java.version>
</properties>

依赖传递:

// 子模块强制引入该依赖
<dependencies>
        <dependency>
             
        </dependency>
</dependencies>



// 子模块 继承,子模块 需要依赖的时候 显示引用,可以不用加版本号,版本号由父pom继承
<dependencyManagement>
    <dependencies>
        <dependency>
        </dependency>
    <dependencies>
</dependencyManagement>

寻找依赖包

maven 在 引入依赖时,必须有 三个坐标 来定位 具体的依赖包。 如果 看到 只有两个坐标,没有 版本号的时候,可以知道,版本号 一定是 在 依赖 中 继承到的。那么可以到 父pom中,或者 父pom 依赖的 包中。

spring boot 正是充分利用了 依赖包管理的特性:

<!-- 一般 spring boot 都会 加入 spring-boot-starter-parent 作为 父pom -->


<!-- spring-boot-starter-parent pom:  -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/>


<!-- spring-boot-starter-parent pom的 父pom: -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.3.12.RELEASE</version>
  </parent>


<!-- spring-boot-dependencies 管理的依赖包: -->

  <dependencyManagement>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>2.3.12.RELEASE</version>
      </dependency>
  </dependencyManagement>


<!-- spring-boot 的依赖: -->

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.2.15.RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

IDEA Maven 依赖插件

Maven Helper

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...