maven插件assembly利用profiles打不同环境发布包


声明:本文转载自https://my.oschina.net/skyzwg/blog/1532238,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

        在使用spring boot开发的时候,会根据环境配置多个application.yml文件(dev,sit等到),在最后发布版本的时候不想把这些不用的配置文件打包到发布包中。在assembly插件的配置文件中也没有找到根据变量排除或加载指定文件的方法,于是就想到了配置多个assembly配置文件(每个配置文件根据环境排查不需要的配置文件),根据pom.xml中的profiles属性指定打包的assembly配置文件。具体的代码如下:

pom.xml中profiles属性配置:

	<profiles> 		<profile> 			<id>dev</id> 			<activation> 				<activeByDefault>true</activeByDefault> 			</activation> 			<properties> 				<profile.assembly.package.suffix>dev</profile.assembly.package.suffix> 			</properties> 		</profile> 		<profile> 			<id>sit</id> 			<properties> 				<profile.assembly.package.suffix>sit</profile.assembly.package.suffix> 			</properties> 		</profile> 	</profiles>

 

pom.xml中assembly插件的配置: (最简化配置)

			<plugin> 				<artifactId>maven-assembly-plugin</artifactId> 				<configuration> 					<appendAssemblyId>false</appendAssemblyId> 					<descriptors> 						<descriptor>src/assembly/package-${profile.assembly.package.suffix}.xml</descriptor> 					</descriptors> 					<finalName>${project.artifactId}-${project.version}</finalName> 				</configuration> 			</plugin> 

 

assembly插件的配置文件:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 		  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> 	<id>customer</id> 	<formats> 		<format>tar.gz</format> 	</formats>  	<fileSets> 		<fileSet> 			<directory>sbin</directory> 			<outputDirectory>/sbin</outputDirectory> 			<useDefaultExcludes>true</useDefaultExcludes> 			<excludes> 				<exclude>mvn_*</exclude> 				<exclude>shutdown.sh</exclude> 				<exclude>startup.sh</exclude> 				<exclude>assembly*</exclude> 			</excludes> 		</fileSet> 		<fileSet> 			<directory>target/classes</directory> 			<outputDirectory>/classes</outputDirectory> 			<excludes> 				<exclude>/com/**/xx/**</exclude>  <!-- 排除某个目录下的所有文件 --> 				<exclude>/com/**/xxxx/**</exclude> 				<exclude>/com/**/xxxxxxx.class</exclude> <!-- 排除某个文件 --> 				<exclude>/static/**</exclude> 				<exclude>/templates/**</exclude> 			</excludes> 			<useDefaultExcludes>true</useDefaultExcludes> 		</fileSet> 		<fileSet> 			<directory>logs</directory> 			<outputDirectory>/logs</outputDirectory> 			<excludes> 				<exclude>/*.log</exclude> 				<exclude>/backup/*.log</exclude> 			</excludes> 			<useDefaultExcludes>true</useDefaultExcludes> 		</fileSet> 	</fileSets> 	<dependencySets> 		<dependencySet> 			<useProjectArtifact>false</useProjectArtifact> 			<outputDirectory>/lib</outputDirectory> 			<excludes> <!-- 排除不需要的依赖包 --> 				<exclude>org.springframework:spring-jdbc</exclude> 				<exclude>org.springframework.boot:spring-boot-starter-jdbc</exclude> 				<exclude>org.springframework.boot:spring-boot-starter-data-jpa</exclude> 				<exclude>org.springframework.boot:spring-boot-starter-redis</exclude> 				<exclude>org.springframework.data:spring-data-jpa</exclude> 				<exclude>org.hibernate.javax.persistence:hibernate-jpa-2.1-api</exclude> 			</excludes> 			<scope>runtime</scope> 		</dependencySet> 	</dependencySets> </assembly> 

 

 

 

 

 

本文发表于2017年09月10日 08:35
(c)注:本文转载自https://my.oschina.net/skyzwg/blog/1532238,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2536 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1