Maven学习笔记-1

1.优势 

  •      约定优于配置
  • 简单
  • 测试支持
  • 构建简单
  • 插件丰富

下载

  • http://maven.apache.org/index.html

maven 根配置

     apache-maven-3.5.4-bin\apache-maven-3.5.4\lib\maven-model-builder-3.5.4.jar  

     解压jar包

    org\apache\maven\model\pom-4.0.0.xml

Maven基础配置

  •   windows : 在path下面配置maven解压路径 
  • Linux  .bash_profile 配置

Maven 最主要的配置文件

    settings.xml

     加载顺序  ~/.m2/setting.xml  > conf/setting.xml 

Setting.xml 标签说明

    localRepository 

          jar仓库存放地址

    interactiveMode       

 <!--Maven是否需要和用户交互以获得输入。如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。-->
 <interactiveMode>true</interactiveMode>

  offline

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->
 <!--表示Maven是否需要在离线模式下运行。如果构建系统需要在离线模式下运行,则为true,默认为false。当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。 -->

    pluginGroups

   <!--当插件的组织Id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId)。当我们使用某个插件,
并且没有在命令行为其提供组织Id(groupId)的时候,Maven就会使用该列表。默认情况下该列表包含了org.apache.maven.plugins和org.codehaus.mojo -->
<!-- pluginGroups | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. |--> <pluginGroups> <!-- pluginGroup | Specifies a further group identifier to use for plugin lookup. <pluginGroup>com.your.plugins</pluginGroup> --> </pluginGroups>

更多的参考 https://blog.csdn.net/u013782203/article/details/51898885

jdk1.8 配置

 <profiles>

   <profile>
      <id>jdk-1.8</id>

      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compiler>1.8</maven.compiler.compiler>
      </properties>
    </profile>
  </profiles>

  pom.xml  

     

<groupId>com.gupao</groupId>   组织
    <artifactId>maven-project</artifactId>  项目名称
    <version>1.0-SNAPSHOT</version>  版本号
<packaging>jar</packaging> 打包方式 默认 jar 支持 jar war pom
dependencyManagement   jar包管理器 只能出现在父类pom 可以帮助统一项目版本号 不会下载jar  当子项目需要的时候 下载jar

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.2.RELEASE</version>
<scope>compile</scope> 五种 compile test provided runtime system
<type>jar</type>
</dependency>
type:相应的依赖产品包形式,如jar,war
scope:用于限制相应的依赖范围,包括以下的几种变量:
compile :默认范围,用于编译
provided:类似于编译,但支持你期待jdk或者容器提供,类似于classpath
runtime:在执行时,需要使用
test:用于test任务时使用
system:需要外在提供相应得元素。通过systemPath来取得
systemPath: 仅用于范围为system。提供相应的路径
optional: 标注可选,当项目自身也是依赖时。用于连续依赖时使用
 
扫描二维码关注公众号,回复: 4806179 查看本文章

  依赖传递  

 

compile

test

provided

runtime

compile

compile

-

-

runtime

test

test

-

-

test

provided

provided

-

provided

provided

runtime

runtime

-

-

runtime

     依赖仲裁

  • 最短路径
  • 加载先后选择   如果先加载 就使用 后面的不会覆盖
  • 排除包 

         

        <exclusions>
            <exclusion>
                <artifactId>commons-beanutils</artifactId>
                <groupId>commons-beanutils</groupId>
            </exclusion>
        </exclusions>

      生命周期

猜你喜欢

转载自www.cnblogs.com/JohnBoy/p/10230364.html