resources目录各环境配置:
env目录:
- local.properties 本地环境
- dev.properties 开发环境
- test.properties 测试环境
- www.properties 生产环境
pom.xml基本内容如下(基于spring-cloud):
<?xml version="1.0"?>
<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>
<parent>
<groupId>cn.xxx</groupId>
<artifactId>xxx-cloud</artifactId>
<version>0.0.2</version>
</parent>
<artifactId>xxx-user-service</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--默认本地环境-->
<package.environment>local</package.environment>
<!--忽略文档打包错误-->
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
</properties>
<profiles>
<profile>
<id>local</id>
<properties>
<package.environment>local</package.environment>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<package.environment>test</package.environment>
</properties>
</profile>
<profile>
<id>www</id>
<properties>
<package.environment>www</package.environment>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-common-core</artifactId>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-cms-model</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-user-model</artifactId>
<version>0.0.3</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-sct-model</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-common-cache</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-base-models</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-common-file</artifactId>
<version>0.0.3</version>
</dependency>
<dependency>
<groupId>cn.xxx</groupId>
<artifactId>xxx-base-service</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- springboot end -->
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>env/*.*</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<detail>true</detail>
<includeEmptyDirs>true</includeEmptyDirs>
<overwrite>true</overwrite>
<encoding>UTF-8</encoding>
<filters>
<filter>${basedir}/src/main/resources/env/${package.environment}.properties</filter>
</filters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<providerImplementations>
<git>jgit</git>
</providerImplementations>
<!--git账号,用于将版本打成tag-->
<username>xxx</username>
<!--git密码-->
<password>xxx</password>
<tagBase>${project.artifactId}-${project.version}</tagBase>
<!-- war不发布到nexus上了 -->
<goals>-f pom.xml package</goals>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-jgit</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<scm>
<connection>scm:git:http://git.xxx.net/xxx-cloud/xxx-user-service.git</connection>
<developerConnection>scm:git:http://git.xxx.net/xxx-cloud/xxx-user-service.git</developerConnection>
<url>http://git.xxx.net/xxx-cloud/xxx-user-service/tree/master</url>
<tag>HEAD</tag>
</scm>
</project>
打生产war包
git pull
mvn release:prepare
如失败:mvn release:rollback
mvn release:perform
如失败,重新执行该命令。
打包生产环境:
mvn clean package -Pwww