Maven打包規範設置

一、技術背景

      在不同的環境,要打不同版本的API包,開發測試環境打SNAPSHOT,線上要打RELEASE包,但是每次都要上線之前都要改代碼,很麻煩,所以用更通用的配置來解決這個問題。

 

二、實現

pom文件配置

    <groupId>com.yx</groupId>
	<artifactId>yx-test-api</artifactId>
	<version>${version.final}</version>
	<name>test-api</name>

	<properties>
        <java.version>1.8</java.version>
		<version.current>1.0.0</version.current>
		<project.version>1.0.0</project.version>
	</properties>
    
    <distributionManagement>
		<repository>
			<id>nexus</id>
			<name>releases</name>
			<url>http:</url>
		</repository>
		<snapshotRepository>
			<id>nexus</id>
			<name>snapshots</name>
			<url>http:</url>
			<uniqueVersion>false</uniqueVersion>
		</snapshotRepository>
	</distributionManagement>
	<repositories>
		<repository>
			<id>Nexus</id>
			<name>Nexus Public Repository</name>
			<url>http:</url>
		</repository>
	</repositories>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.2</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>findbugs-maven-plugin</artifactId>
				<version>3.0.0</version>
			</plugin>
			<plugin>
				<artifactId>maven-source-plugin</artifactId>
				<executions>
					<execution>
						<id>attach-sources</id>
						<phase>package</phase>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

        <profiles>
		<profile>
			<id>dev</id>
			<properties>
				<active>dev</active>
				<version.final>${version.current}-SNAPSHOT</version.final>
			</properties>
		</profile>
		<profile>
			<id>test</id>
			<properties>
				<active>test</active>
				<version.final>${version.current}-RELEASE</version.final>
			</properties>
			<activation>
				<!-- 默認環境 -->
				<activeByDefault>true</activeByDefault>
			</activation>
		</profile>
		<profile>
			<id>prod</id>
			<properties>
				<active>prod</active>
				<version.final>${project.version}-RELEASE</version.final>
			</properties>
		</profile>
	</profiles>

其中<active> 標籤,是根據application.properties的配置

#環境
spring.profiles.active=@active@

標籤內dev,test,prod取值

根據不同環境的配置名稱,如下圖

 

參考大佬:

Spring boot 使用profile完成不同環境的maven打包功能

使用maven profile 指定配置打包

springboot多環境(dev、test、prod)配置

idea配置springBoot多環境

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章