maven

POM

只挑重点,其他慢慢补充,或许永远也不补充了
参考链接:https://maven.apache.org/pom.html#What_is_the_POM

overlook

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <!-- The Basics -->
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>
  <dependencies>...</dependencies>
  <parent>...</parent>
  <dependencyManagement>...</dependencyManagement>
  <modules>...</modules>
  <properties>...</properties>

  <!-- Build Settings -->
  <build>...</build>
  <reporting>...</reporting>

  <!-- More Project Information -->
  <name>...</name>
  <description>...</description>
  <url>...</url>
  <inceptionYear>...</inceptionYear>
  <licenses>...</licenses>
  <organization>...</organization>
  <developers>...</developers>
  <contributors>...</contributors>

  <!-- Environment Settings -->
  <issueManagement>...</issueManagement>
  <ciManagement>...</ciManagement>
  <mailingLists>...</mailingLists>
  <scm>...</scm>
  <prerequisites>...</prerequisites>
  <repositories>...</repositories>
  <pluginRepositories>...</pluginRepositories>
  <distributionManagement>...</distributionManagement>
  <profiles>...</profiles>
</project>

Maven Coordinates

groupId: 公司或者组织的标识 一般都是域名来着
artifactId: groupId下的确定项目
version: 版本
这三者指明了一个确定版本的项目,让maven知道我们在处理谁

packaging

<packaging>jar</packaging>

打包方式:pom,jar,maven-plugin,ejb,war,ear,rar

POM Relationships

处理依赖关系

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      https://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>
    ...
  </dependencies>
  ...
</project>

classifier:???
type:所选依赖的类型
scope:作用域,用于限制依赖的传递性

  • compile(默认): 编译,测试,运行
  • provided: 编译和测试,打包的时候不用打包进去,别web container 会提供
  • runtime: 测试和运行,不编译,与compile相比,只是跳过编译
  • test:仅参与测试
  • system: 类似于provided

optional:消除当前的传递依赖,就是说当前项目A是依赖的,但是依赖此项目的B是不依赖与此项的。

Dependency Version Requirement Specification

mark一下,不过携程貌似都是指明的

  • 1.0:"Soft" requirement on 1.0 (just a recommendation, if it matches all other ranges for the dependency)
  • [1.0]: "Hard" requirement on 1.0
  • (,1.0]: x <= 1.0
  • [1.2,1.3]: 1.2 <= x <= 1.3
  • [1.0,2.0): 1.0 <= x < 2.0
  • [1.5,): x >= 1.5
  • (,1.0],[1.2,): x <= 1.0 or x >= 1.2; multiple sets are comma-separated
  • (,1.1),(1.1,): this excludes 1.1 (for example if it is known not to work in combination with this library)
    详情见参考链接

Exclusions

指明当前说我不要什么传递依赖

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      https://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-embedder</artifactId>
      <version>2.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    ...
  </dependencies>
  ...
</project>

父项目

<parent>                父项目坐标,一些初始值
   <groupId/>           公司或者组织的标识 一般都是域名来着
   <artfactId/>         groupId下的确定项目
   <version/>           版本
   <relativePath />     父项目的相对路径。(若没有则,优先级为上级目录,本地仓库,远程仓库)
</parent>

本项目

<groupId/>
<artfactId/>
<version/>
同父项目,就是本项目的配置

<packaging/> 打包方式

项目依赖

<dependencies> 们
    <dependency>
        <groupId/>
        <artfactId/>
        <version/>
        <scope/> 作用域 compile,provided,runtime,test,system
        <optional>
    <dependency>
</dependencies>
添加新评论