Maven知识点简要

1、依赖管理

<dependencies>
<dependency>
  <groupId>net.sf.json-lib</groupId>
  <artifactId>json-lib</artifactId>
  <version>2.2.2</version>
  <type>jar</type>
       <optional>true</optional>    依赖不传递
  <scope>compile</scope>   scope  compile:默认   test:测试包下可以,打包不加入,比如:junit    provided:编译和测试的依赖,打包不加入,比如:servlet-api
</dependency>
</dependencies>
dependencies与dependencyManagement区别

dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)

dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。

2、阿里镜像,修改settings

<mirrors>
<mirror>

<id>alimaven</id>

<name>aliyun maven</name>

<url>http://maven.aliyun.com/nexus/content/groups/public/</url>

<mirrorOf>central</mirrorOf>

</mirror>

</mirrors>

3、聚合与继承

聚合
一般聚合项目用<packaging>pom</packaging>
聚合项目与子项目平行目录结构的配置
<modules>
<module>../subModule1</module>
<module>../subModule2</module>
</modules>
继承
<perent>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<relativePath></relativePath>
</parent>
父模块dependencyManagement中定义的依赖:不会为父模块和子模块实际依赖,必须在子模块定义实际定义才行,而dependencies为导致父模块和所有子模块的依赖不必要的资源;pluginManagement和plugins有相同的道理

4、maven将本地jar包添加到本地仓库

maven在pom文件里引用本地jar

方法1:

    <dependency> 
        <groupId>org.wltea</groupId> 
        <artifactId>IKAnalyzer</artifactId> 
        <version>2012_u6</version> 
        <scope>system</scope> 
        <systemPath>E:/repositories/IKAnalyzer2012_u6.jar</systemPath> 
    </dependency>

方法2:
到maven/bin 路径下,启动cmd窗口,执行 命令: 
 mvn install:install-file -Dfile=rest-2.6.3.jar -DgroupId=com.cloopen -DartifactId=rest -Dversion=2.6.3 -Dpackaging=jar 
mvn install:install-file -Dfile=jar包的位置 -DgroupId=一般是公司名倒序 -DartifactId=唯一型ID -Dversion=版本号 -Dpackaging=jar  
IDEA命令拉取jar包源码:

执行mvn命令:
下载所有pom依赖包的source:mvn dependency:resolve -Dclassifier=sources
下载指定依赖包的source:mvn dependency:sources -DincludeArtifactIds=guava
其中guava为ArtifactId

5, install 和 package的区别

package will compile your code and also package it. For example, if your pom says the project is a jar, it will create a jar for you when you package it and put it somewhere in the target directory (by default).

install will compile and package, but it will also put the package in your local repository. This will make it so other projects can refer to it and grab it from your local repository.

总的来说:
package = 编译+打包
install = 编译+打包+入本地库,打完包之后能够被其他项目依赖到。

6、编译项目跳过 jacoco 方案:  skipTests配置为true,并在terminal执行  mvn clean verify 。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值