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

        在使用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>

 

执行命令:

mvn -f $Project_HOME/pom.xml clean assembly:assembly -DskipTests  #跳过测试

 

 

 

转载于:https://my.oschina.net/skyzwg/blog/1532238

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值