基本信息:
<modelVersion>4.0.0</modelVersion> :Maven3固定不变
<groupId>com.netqin.framework</groupId> :定义项目隶属于哪个组,是一个实际的项目
<artifactId>frame-core</artifactId> :项目模块名称
<packaging>jar</packaging> :打包方式,默认jar,可以配置war,pom(聚合项目)
<version>0.0.1-SNAPSHOT</version>:项目版本
<name>netqin foamework core</name> :项目一个比较易读的名称
<url>http://maven.apache.org/frame-core</url> :项目访问地址
聚合项目:
<modelVersion>4.0.0</modelVersion>
<groupId>com.netqin.framework</groupId>
<artifactId>frame-framework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>netqin foamework</name>
<url>http://maven.apache.org</url>
<modules>
<module>frame-core</module>
<module>frame-service</module>
</modules>
子模块:
<modelVersion>4.0.0</modelVersion> :无论聚合项目还是子项目,都必须包含该配置
<parent>
<artifactId>frame-framework</artifactId>
<groupId>com.netqin.framework</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>frame-core</artifactId>:其余属性默认与父模块相同
<packaging>jar</packaging>
<name>netqin foamework core</name>
<build>
<finalName>frame-core</finalName>:生成的包的名称
</build>
聚合和子模块都可以配置如下内容:
1.属性
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
2.依赖
<dependencies>
<dependency>
<groupId>spring</groupId>
<artifactId>spring-core</artifactId>
<version>1.0.2</version>:以上三项为必填项,version在子模块继承时可以不用声明
<type>jar</type>:依赖类型,默认为jar,对应于项目的packaging,一般不用声明
<scope>compile</scope>:依赖范围,默认compile,编译、测试、运行都有效,比如spring-core
<optional>true</optional>:可选依赖,既只对当前项目有效,不会传递给子模块
<exclusions>:排除依赖,既排除掉当前依赖下对应依赖包,既项目编译时不会导入该依赖包,可以在下面声明一个高级版本进行替换
<exclusion>
<groupId>com.test.demo</groupId>
<artifactId>demo-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.test.demo</groupId>
<artifactId>demo-core</artifactId>
<version>1.0.2</version>:换个高级版本
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<scope>test</scope>:只对测试范围有效,比如Junit。
另外还可配置provided:编译和测试有效,运行无效,比如servlet-api。
runtime:测试和运行时有效。
import:导入其它pom中的<dependencyManagement>,该元素只在<dependencyManagement>中可以使用,如下内容介绍。
</dependency>
</dependencies>
dependencies:会被子模块继承,如果不希望子模块继承,可以使用如下配置:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${juint.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>1.0.0version>
<type>pom</type>:只能是pom
<scope>import</scope>:将该坐标对应的聚合项目中的<dependencyManagement>合并到当前的<dependencyManagement>中来
</dependency>
</dependencies>
</dependencyManagement>
<dependencyManagement>:被该元素包裹起来的依赖不会被子模块继承,
如果子模块中要使用,需要在dependencies中声明,但这时可以之生命groupId和artifactId,比如:
3.插件
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>:绑定clean生命周期
<goals>
<goal>clean</goal>:绑定clean生命周期的clean目标
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
上述配置,子模块也会继承,类似<dependencyManagement>,如果不希望子模块继承,可以如下配置:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
子模块只要如下配置即可:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
插件需要绑定到某个生命周期才可以使用
依赖项目命令:
1.查看当前项目的已解析依赖,类似于eclipse的pom查看器中的Dependency Hierarchy的右侧视图
mvn dependency:list
2.查看当前项目的已解析依赖,类似于eclipse的pom查看器中的Dependency Hierarchy的左侧视图
mvn dependency:tree
3.查看项目使用了但是依赖没有声明,或者是声明了没有使用
mvn dependency:analyze
比如,没有使用到spring-core,但是项目中声明了
[WARNING] Unused declared dependencies found:
[WARNING] org.springframework:spring-core:jar:3.0.6.RELEASE:compile
分享到:
相关推荐
maven-parent-pom-0.1.0.jar
解决tomcat8-maven-plugin-3.0-r1655215.jar阿里云同有的问题。放到路径org\apache\tomcat\maven\tomcat8-maven-plugin\3.0-r1655215\就可以了
maven-pom-plugin-1.4.jar
maven-assembly-plugin-2.2-beta-5.jar
maven-archetype-webapp-1.0.jar,下载,如果有需要的同志可以自己下载,。
maven-resources-plugin-2.4.1.jar
maven资源 apache-maven-3.3.9-bin.zip
maven-pom-plugin-1.3.jar
maven-timestamp-plugin-1.0.jar
2.cmd窗口执行mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar -Dfile=maven-archetype-quickstart-1.1.jar
maven编译pentaho-big-data-plugin遇到的所有问题解决,pentaho6.0
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
java运行依赖jar包
zookeeper云的学习笔记-云的学习笔记系统-云的学习笔记系统源码-云的学习笔记管理系统-云的学习笔记管理系统java代码-云的学习笔记系统设计与实现-基于ssm的云的学习笔记系统-基于Web的云的学习笔记系统设计与实现-...
Maven更新问题 今天Maven在更新的时候发现一直更新不成功,总结下解决方法。 在apache-maven-3.5.2/conf/setting.xml中加入以下配置即可解决 alimaven aliyun maven ...
maven是个项目管理工具,如果我们不告诉它我们的代码要使用什么样的jdk版本编译的话,它就会用maven-compiler-plugin默认的jdk版本来进行处理,这样就容易出现版本不匹配,以至于可能导致编译不通过的问题。...