Maven学习札记

来源:互联网 发布:使用sci hub 知乎 编辑:程序博客网 时间:2024/05/19 16:33

***********************************************声明******************************************************

      原创作品,出自 “晓风残月xj” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/xiaofengcanyuexj)。

      由于各种原因,可能存在诸多不足,欢迎斧正!

********************************************************************************************************* 

1、dependencies 和 dependencyManagement 的区别在于
1.1)、dependencies:即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项。

1.2)、dependencyManagement:如果在子项目中不写该依赖项,那么子项目中是不会从父项目继承该依赖项的;只有在子项目中写了该依赖项,才会从父项目中继承该项,并且version 和 scope 都读取自 父pom。


2、exclusions标签的作用

exclusions:在exclusions来排除相关的传递依赖或者配置,避免依赖冲突或者不加载。

<dependency>            <groupId>org.springframework</groupId>            <artifactId>spring-webmvc</artifactId>            <version>2.5.6</version>      <exclusions>                <exclusion>                    <groupId>org.springframework</groupId>                    <artifactId>spring-beans</artifactId>                </exclusion>                <exclusion>                    <groupId>org.springframework</groupId>                    <artifactId>spring-context</artifactId>                </exclusion>                <exclusion>                    <groupId>org.springframework</groupId>                    <artifactId>spring-core</artifactId>                </exclusion>                <exclusion>                    <groupId>org.springframework</groupId>                    <artifactId>spring-web</artifactId>                </exclusion>            </exclusions>        </dependency></span>

3、maven项目中groupId与artifactId
groupId:项目组织唯一的标识符,一般是域名的反写,是main目录里java的目录结构;

artifactId:项目的唯一的标识符,对应项目的名称,就是项目根目录的名称。


4、delpoy标签
mvn:deploy在整合或者发布环境下执行,将最终版本的包拷贝到远程的repository,使得其他的开发者或者工程可以共享。

<properties>    skip_maven_deploy>true</skip_maven_deploy></properties>
表示maven部署的时候跳过该工程。


5、<modules>模块

一个项目可以由多个模块组成,通过一个父POM 引用一个或多个子模块来定义,如下:

<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/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.alibaba</groupId><artifactId>dubbo-parent</artifactId><version>2.5.4-SNAPSHOT</version></parent><artifactId>dubbo-test</artifactId><packaging>pom</packaging><name>${project.artifactId}</name><description>The test module of dubbo project</description><properties><skip_maven_deploy>true</skip_maven_deploy></properties><modules><module>dubbo-test-benchmark</module><module>dubbo-test-compatibility</module><module>dubbo-test-integration</module>                <module>dubbo-test-examples</module></modules></project>
</pre><p><strong></strong></p><strong><span style="font-family:Verdana; font-size:14px">6、<profiles>配置文件</span></strong><p></p><p><span style="font-family:Verdana; font-size:14px">     profile定义配置文件信息,并指定其激活条件。同一个profiles可以定义多个profile,然后每个profile对应不同的激活条件和配置信息,从而达到不同环境使用不同配置信息的效果。<a target=_blank target="_blank" href="http://haohaoxuexi.iteye.com/blog/1900568">profile详情</a></span></p><p><span style="font-family:Verdana; font-size:14px"></span></p><pre code_snippet_id="1569165" snippet_file_name="blog_20160129_4_9894952" name="code" class="html"><profiles><profile><id>test</id><activation><file><missing>.project</missing></file></activation><modules><module>dubbo-test</module></modules></profile><profile><id>hudson</id><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><testFailureIgnore>true</testFailureIgnore></configuration></plugin></plugins></build></profile></profiles>

其中<activation>制定激活条件。


7、<plugins>插件

plugins是处理与依赖相关的插件。有很多可用的目的,大部分是和依赖构建、分析和解决相关的。详情

<build>     <plugins><plugin><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>unpack</id><phase>package</phase><goals><goal>unpack</goal></goals><configuration><artifactItems><artifactItem><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>${project.parent.version}</version><outputDirectory>${project.build.directory}/dubbo</outputDirectory><includes>META-INF/assembly/**</includes></artifactItem></artifactItems></configuration></execution></executions></plugin><plugin><artifactId>maven-assembly-plugin</artifactId>                <configuration>                    <descriptor>src/main/assembly/assembly.xml</descriptor>                </configuration>                <executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions>            </plugin></plugins></build>

8、<packaging>打包

  打包的机制,如pom, jar, maven-plugin, ejb, war, ear, rar, par等,如多module的工程中最外层pom.xml的打包方式就是pom

<packaging>pom</packaging>

9、<resources>资源

maven项目中需要指定的资源,如:spring配置文件目录resource

 <build>        <resources>            <resource>                <directory>${basedir}/src/main/java</directory>                <excludes>                    <exclude>**/*.java</exclude>                </excludes>            </resource>            <resource>                <directory>${basedir}/src/main/resources</directory>            </resource>        </resources>    </build>



                















0 0
原创粉丝点击