maven基础

来源:互联网 发布:sql trunc函数 编辑:程序博客网 时间:2024/05/24 04:42

mvn标签

<groupId>反写公司网址+项目名称</groupId>

<artifactId>项目名称+模块名称</artifactId>

<version>前面一般有三位数组

第一位标示大版本号

第二位标示分支版本号

第三位标示晓版本号

0.01

snapshot快照

alpha内部测试

beta公测

Release稳定

GA正式发布


0.01snapshot

</version>

<packaging>

默认是jar

还可以是:war zip pom

</packaging>


<name>项目描述名称</name>

<url></url>项目地址

<description></description>项目描述

<developers></developers>开发者列表

<licensers></licensers>项目的证书

<organization></organization>公司组织


<dependencies>

<dependency>

<groupId></groupId>

<artifactId></artifactId>

<version></version>

<type></type>

scope的集中选择

1compile:默认范围,编译测试运行都有效

2provided:编译测试时都有效

3runtime:测试运行时有效

4test:只在测试时有效

5system:与本机系统相关联,可移植性差

6import:导入的范围,它只是用杂dependencyManagement中,标示从其他的pom中导入dependency的配置

<scope></scope>

设置以来是否可选,true标示可以从父亲那继承得到,false表示需要显示的声明

<optional></optional>

排除依赖传递列表

<executions>
         <execution>

</execution>

</executions>

</dependency>

</dependencies>

依赖管理,用在父pom文件中,该配置在运行时不起作用,当子pom文件能拿到这些依赖,子pom文件配置依赖的时候不需要写version,一般父pom文件的<packaging>属性会设置为pom

<dependencyManagement>

<dependencies>

</dependencies>

</dependencyManagement>


<build>

插件列表

<plugins>

<plugin>

<groupId></groupId>

<artifactId></artifactId>

<version></version>


</plugin>

</plugins>

定义一些配置,比如环境变量等

<profile>


</profile>


如果maven中发现了连个相同的jar包,版本不同

最短路径优先

先声明优先



maven几个阶段

mvn compile 编译

mvn test  测试

mvn package  打包

mvn clean 删除target目录

mvn install  安装jar包到本地仓库


将maven_home\bin配置到path路径下,在maven项目目录下运行mvn dependency:tree可查看jar包依赖树


mvn archetype:generate 生成mvn项目骨架

mvn archetype:generate -Dgroupid= xxx   -DartifactId=xxx   -Dversion=xxx -Dpackage=xxx

-src

     -main

          -java

              -package

   -test 

         -java

               -package


仓库

本地仓库  在maven安装目录下的conf/setting.xml 中配置  <localRepository>d:\\.m2\repository</localRepository>

中央仓库  在maven_home/lib/maven-model-builder-3.3.9.jar 里面有个org/apache/maven/model/pom-4.0.0.xml文件,它定义了maven的中央仓库

<repositories>
    <repository>
      <id>central</id> (中央参考的唯一标识)
      <name>Central Repository</name> (参考名称)
      <url>https://repo.maven.apache.org/maven2</url> (仓库地址)
      <layout>default</layout>   (布局)
      <snapshots>
        <enabled>false</enabled>  (是否允许下载快照版本)
      </snapshots>
    </repository>
  </repositories>


有时候仓库在 国外,或者由于某种原因访问不到,可以为该参考设置镜像,那么以后访问的时候就访问镜像仓库地址

镜像

  <mirrors>

 <mirror>
      <id>CN</id>
      <name>OSChina Central</name>
      <url>http://maven.oschina.net/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

一般用阿里云的镜像

<mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>

激活profile

  <activeProfiles>
    <activeProfile>repo2</activeProfile>
<activeProfile>osc</activeProfile>

  </activeProfiles>

如果有两个profile处于激活转态,那使用mvn compile的时候 会用哪个profile呢,答案是会使用定义靠后的那个,比如,repo2和osc,两个都处于激活转态,因此mvn编译的时候选用定义靠后的那个



maven 下载依赖的源代码

 mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true 


0 0
原创粉丝点击