工作笔记-Maven继承:创建一个Parent工程

继承是Maven三大特点之一,创建一个Parent工程方便集中管理依赖关系和配置构建。

可以通过几个标签来配置父工程。

1. dependencyManagement

在<dependencyManagement>中配置的依赖和版本,在所有子工程中都有效。

<dependencyManagement>
		<dependencies>
			<!-- netty -->
			<dependency>
				<groupId>io.netty</groupId>
				<artifactId>netty-all</artifactId>
				<version>4.0.42.Final</version>
			</dependency>
			<!-- netty end -->
			<!-- spring mvc -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>3.2.4.RELEASE</version>
			</dependency>
		</dependencies>
</dependencyManagement>

子工程中再配置<dependency>及<version>, 可以覆盖父类的配置。

2. <pluginManagement>

类似<dependencyManagement>这个标签的作用是配置plugin并在所有子工程中生效。同样在子类中的详细配置可以覆盖父类中的配置。

<build>
    <pluginManagement>
        <plugins>
        <!--打包时跳过测试 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>true</skipTests>
			    </configuration>
			</plugin>
			<!--默认plugin: maven-resources-plugin, maven-compiler-plugin, maven-war-plugin -->
		</plugins>
	</pluginManagement>
</build>

3. <repositories>

远程代码仓不需要在每一个模块中都配置一遍,在父类中配置好就可以了。

<repositories>
		<repository>
			<id>aliyunmaven</id>
			<name>阿里云中央仓库</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>

4. <distributionManagement>

同理。

一个完整的Maven  Parent配置示例

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<name>Netbar-parent</name>
	<description>Nerbar Parent Project</description>
	<groupId>cn.jim</groupId>
	<artifactId>Netbar-parent</artifactId>
	<version>1.0.0</version>
	<packaging>pom</packaging>

	<dependencyManagement>
		<dependencies>
			<!-- netty -->
			<dependency>
				<groupId>io.netty</groupId>
				<artifactId>netty-all</artifactId>
				<version>${netty.version}</version>
			</dependency>
			<!-- netty end -->
			<!-- spring mvc -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-context-support</artifactId>
				<version>${spring.version}</version>
			</dependency>
			<!-- spring mvc end -->
		</dependencies>
	</dependencyManagement>
	<build>
		<pluginManagement>
			<plugins>
				<!--打包时跳过测试 -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-surefire-plugin</artifactId>
					<version>2.12.4</version>
					<configuration>
						<skipTests>true</skipTests>
					</configuration>
				</plugin>
				<!--默认plugin: maven-resources-plugin, maven-compiler-plugin, maven-war-plugin -->
			</plugins>
		</pluginManagement>
	</build>
	<repositories>
		<repository>
			<id>aliyunmaven</id>
			<name>阿里云中央仓库</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>
	<distributionManagement>
		<repository></repository>
		<snapshotRepository></snapshotRepository>
	</distributionManagement>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<netty.version>4.0.42.Final</netty.version>
		<spring.version>3.2.4.RELEASE</spring.version>
		<cxf.version>2.7.0</cxf.version>
		<quartz.version>2.2.3</quartz.version>
		<slf4j-version>1.7.12</slf4j-version>
	</properties>
</project>

总结

创建一个parent工程,将比较统一的配置放在parent中,方便管理,推荐的标签:<dependencyManagement><pluginManagement><repositories><distributionManagement>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
build-helper-maven-plugin:jar:1.8是一个用于构建Java项目的Maven插件。该插件提供了一些辅助功能,以帮助简化和优化项目构建过程。 首先,build-helper-maven-plugin:jar:1.8可以帮助我们在构建过程中处理一些非常规的任务。例如,它可以通过添加额外的源代码目录来扩展项目的结构,以便在构建过程中包含其他源代码。这对于多模块项目或需要集成外部代码库的项目非常有用。 此外,该插件还提供了一些用于处理资源文件的功能。我们可以使用该插件来复制或移动资源文件到特定的目录,以便在构建过程中正确地包含这些文件。这对于需要在构建期间处理和转换资源文件的项目非常有用,例如压缩JavaScript或CSS文件。 另一个重要的功能是build-helper-maven-plugin:jar:1.8可以帮助我们在构建过程中处理依赖关系。它可以自动将特定的依赖项添加到项目配置中,以便在编译和运行时正确地解决这些依赖项。这对于需要从其他模块或项目引入代码或库的项目非常有用。 除了以上提到的功能,build-helper-maven-plugin:jar:1.8还提供了其他一些辅助功能,如将构建生成的文件添加到构建输出中,生成版本号等。 综上所述,build-helper-maven-plugin:jar:1.8是一个功能强大的Maven插件,可以帮助我们更轻松地构建和管理Java项目。通过提供一些辅助功能,它提高了项目的灵活性和可维护性,使我们能够更加高效地进行构建过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值