build
build下的子元素pluinins用来声明插件。因为maven 2.1默认用jdk 1.3来编译,maven 3 貌似是用jdk 1.5,所以有时候在maven编译的过程中会出现jdk版本低的提示,就可以在此处声明jdk的版本。<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <vesion>2.1</vesion> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build>
- dependencyManagenment
。dependencyManagenment声明的依赖既不会实际引入到父模块,也不会引入到子模块中。那它有什么用?答案就是对依赖项进行管理,Maven继承中子模块会继承父模块的依赖项,这就容易导致依赖项冲突,因此比较统一的管理依赖项会大大改善这种情况。如何使用呢?比如在父模块的POM文件中有一个junit依赖
<dependencyManagement>
<dependencies>
....
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
....
</dependencies>
</dependencyManagement>
然后子模块恰好需要juit依赖:
<dependencies>
<groupId>junit<groupId>
<artifactId>junit</artifactId>
</dependencies>
这样就足够了,version和scope会从父模块的pom中继承。
3. pluginManagement
pluginManagement对插件的管理与dependencyManagement对依赖类似,pluginManagement下声明的插件不会被父模块和子模块实际调用。比如在父模块pluginManagement下声明了maven-resources-plugin插件
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugubs</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</bulid>
在子模块中如需要调用词插件则可以使用以下声明:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugubs</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
这样就可以了