余瑜的博客 余瑜的博客
首页
  • 并发
  • 线程池
  • spring
  • maven
  • 其他
  • redis
  • mysql
  • linux
  • zookeeper
  • docker
  • terminal
  • kong插件开发
  • 资料
  • leetCode-简单
  • blog
  • 其他
关于
GitHub (opens new window)
首页
  • 并发
  • 线程池
  • spring
  • maven
  • 其他
  • redis
  • mysql
  • linux
  • zookeeper
  • docker
  • terminal
  • kong插件开发
  • 资料
  • leetCode-简单
  • blog
  • 其他
关于
GitHub (opens new window)
  • 并发

  • 线程池

  • spring

  • maven

    • maven
      • 模板
        • 基本配置
    • maven-optional可选依赖
    • maven查看依赖
    • 神器:maven脚手架
  • 其他

  • JAVA
  • maven
余瑜
2018-03-11
目录

maven

此资料从官网摘取

# 模板

<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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# 基本配置

modelVersion
Maven模块版本,目前我们一般都取值4.0.0
groupId
分组名称,一般域名倒叙。
artifactId
项目名称或子模块名称。
version
版本号
  • *-SNAPSHOT 不稳定版本
    • 存放在快照仓库,构建时远程抓取
  • *-RELEASE 稳定版本
    • 存放在正式仓库,构建的时会先在本次仓库中查找是否已经有了这个依赖库,如果没有的话才会去远程仓库中去拉取
name
项目名称
description
项目描述
packaging
打包类型,可取值:jar,war,maven-plugin等等,这个配置用于package的phase,具体可以参见package运行的时候启动的plugin,

# parent

继承父类

    <parent>
        <groupId>com.yuyu</groupId>
        <artifactId>yuyu-nexus-parent-pom</artifactId>
        <version>0.0.2.RELEASE</version>
1
2
3
4

# modules

声明子模块

	<modules>
		<module>sales-mall</module>
		<module>sales-middle</module>
	</modules>

1
2
3
4
5

# Dependencies

项目所需要的依赖包

groupId
依赖项的groupId
artifactId
依赖项的artifactId
version
依赖项的版本
scope
依赖项的适用范围:
  • compile,缺省值,适用于所有阶段,会随着项目一起发布。
  • provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
  • runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
  • test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
  • system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。之前例子里的junit就只用在了test中。
exclusions
排除项目中的依赖冲突时使用。
# exclusions
  1. 排除告诉Maven不要包括指定的项目依赖的这种依赖性(换句话说,它的传递依赖)。例如,maven-embedder需要maven-core,我们不希望使用它或其依赖项,然后我们将它排除。
 <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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  1. 它有时也有用片段依赖的传递依赖关系。依赖可能错误地指定的范围,与其他依赖或依赖项冲突在您的项目。使用通配符不便于排除所有依赖的传递依赖项。在下面的情况下你可能会使用maven-embedder和你想管理依赖你自己使用,所以你剪辑传递依赖关系:
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-embedder</artifactId>
      <version>3.1.0</version>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
1
2
3
4
5
6
7
8
9
10
11

# build

构建

<build>
    <finalName>sales-middle-service</finalName>
      <resources>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
             <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>${project.basedir}/src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
finalName 项目打包后的名字
resources 配置文件
filter 可以把属性写到文件里,用属性文件里定义的属性做替换
上次更新: 2021/02/16, 15:47:09

← spring源码阅读神器 maven-optional可选依赖→

Theme by Vdoing | Copyright © 2018-2022 逆光世间 | 备案号: 京ICP备19016086号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式