首页  

maven知识点整理     所属分类 maven 浏览量 1155
仓库
本地(local)
远程(remote)  

依赖 library jar、plugin jar

本地仓库默认  ${user.home}/.m2/repository 

settings.xml  设置
localRepository

中央仓库
私有仓库

中央仓库配置

<profiles>
        <profile>  
            <id>central</id>  
            <repositories>
                <repository>
                    <id>Central</id>
                    <name>Central</name>
                    <url>http://repo.maven.apache.org/maven2/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>central</activeProfile>
    </activeProfiles>


Mirror


<mirrors>
    <mirror>
      <id>mirrorid</id>
      <mirrorOf>central</mirrorOf>
      <name>one of the central mirrors</name>
      <url>xxx</url>
    </mirror>
  </mirrors>


mirrorOf  central  *


坐标 GAV  groupId artifactId version

groupId:表示一个团体,可以是公司、组织等
artifactId:表示团体下的某个项目
version:表示某个项目的版本号

依赖 传递 冲突 
两种冲突处理策略
短路优先
声明优先

依赖排除

<exclusions>
    <exclusion>
        <groupId>excluded.groupId</groupId>
        <artifactId>excluded-artifactId</artifactId>
    </exclusion>
</exclusions>


冲突导致的 NoSuchMethodError

mvn dependency:tree -Dverbose -Dincludes=javax.servlet:servlet-api


冲突 NoSuchMethodError 解决思路

找到冲突的jar包
确认正确的和错误的jar
打印依赖树
正确的依赖优先声明
排除错误的依赖包


依赖管理
多模块聚合 packaging  pom
继承  parent 
parent dependencyManagement 声明版本,子项目不需要版本

常用maven命令
mvn -version
mvn compile 编译源码
mvn package 打包 生成 jar 或 war
mvn test
mvn install  把jar包复制到本地仓库
mvn deploy  发布到远程仓库
mvn eclipse:eclipse 
mvn dependency:tree
mvn tomcat:run
mvn jetty:run

mvn dependency:analyze-only

[WARNING] Used undeclared dependencies found:
[WARNING] Unused declared dependencies found:



mvn package -Dmaven.test.skip=true


-P 指定Profile

一般分开发,测试,预发,正式4个环境


<profiles>
  <profile>
     <id>dev</id>
     <properties>
        <env>dev</env>
     </properties>
     <activation>
        <activeByDefault>true</activeByDefault>
     </activation>
  </profile>
  <profile>
     <id>qa</id>
     <properties>
         <env>qa</env>
     </properties>
  </profile>
  <profile>
     <id>pre</id>
     <properties>
        <env>pre</env>
     </properties>
  </profile>
  <profile>
     <id>prod</id>
     <properties>
        <env>prod</env>
     </properties>
  </profile>
</profiles>
 
...
 
<build>
  <filters>
        <filter>config/${env}.properties</filter>
  </filters>
  <resources>
     <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
     </resource>
  </resources>
</build>



mvn package -P dev


-e 显示maven运行出错的信息
-o 离线执行命令,即不去远程仓库更新包
-X 显示maven允许的debug信息
-U 强制去远程更新snapshot的插件或依赖,默认每天只更新一次

上一篇     下一篇
springboot2获取web端口

springboot2微服务实例

springcloud DiscoveryClient使用说明

springboot打包成可执行jar

springboot打包排除配置文件

springboot序列化异常FAIL_ON_EMPTY_BEANS处理