Parcourir la source

maven多环境打包配置

zouguihou il y a 2 ans
Parent
commit
257294cb7c

+ 41 - 1
pom.xml

@@ -100,9 +100,40 @@
             <version>1.2.33</version>
         </dependency>
     </dependencies>
+
+    <!-- maven多环境打包配置 -->
+    <profiles>
+        <!-- 开发环境 -->
+        <profile>
+            <id>dev</id>
+            <properties>
+                <spring.profiles.active>dev</spring.profiles.active>
+            </properties>
+            <!-- 设置为默认环境 -->
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+        </profile>
+        <!-- 生产环境 -->
+        <profile>
+            <id>prod</id>
+            <properties>
+                <spring.profiles.active>prod</spring.profiles.active>
+            </properties>
+        </profile>
+        <!-- 测试环境 -->
+        <profile>
+            <id>test</id>
+            <properties>
+                <spring.profiles.active>test</spring.profiles.active>
+            </properties>
+        </profile>
+    </profiles>
+
     <!--添加maven插件,项目的打包工具,打成jar包,否则在打包运行时报错   -->
     <build>
-        <finalName>CIS</finalName>
+        <!-- 打包名格式:项目名-环境-打包时间.jar -->
+        <finalName>${project.artifactId}-${spring.profiles.active}</finalName>
         <resources>
             <resource>
                 <directory>src/main/java</directory>
@@ -119,6 +150,7 @@
                     <include>**/*.yml</include>
                     <include>**/*.properties</include>
                 </includes>
+                <filtering>true</filtering>
             </resource>
         </resources>
         <plugins>
@@ -141,6 +173,14 @@
                     </execution>
                 </executions>
             </plugin>
+            <!-- maven 打包时跳过测试 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <skipTests>true</skipTests>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 </project>

src/main/resources/application.yml → src/main/resources/application-dev.yml


+ 36 - 0
src/main/resources/application-prod.yml

@@ -0,0 +1,36 @@
+server:
+  port: 8088
+  servlet:
+    context-path: /welampiot
+
+spring:
+  application:
+    name: welampiot
+  datasource:
+#    driver-class-name: com.mysql.jdbc.Driver
+    url: jdbc:mysql://139.196.213.241:3306/welampiot?characterEncoding=utf-8&useSSL=false
+    username: welampiot
+    password: welampiot@2023
+    initialSize: 5
+    minIdle: 5
+    maxActive: 100
+    maxWait: 60000
+    #数据库连接中数据源类型
+    type: com.alibaba.druid.pool.DruidDataSource
+#  jackson:
+#    serialization:
+#      write-null-map-values: true
+#  gson:
+#    serialize-nulls: true
+mybatis:
+  mapper-locations: classpath:/mapper/*.xml
+  check-config-location: true
+  type-aliases-package: com.welampiot
+debug: false
+
+logging:
+  file:
+    path: /logs/cis
+  level:
+      root: info
+  config: classpath:logback.xml

+ 38 - 0
src/main/resources/application-test.yml

@@ -0,0 +1,38 @@
+server:
+  port: 8088
+  servlet:
+    context-path: /welampiot
+
+spring:
+  application:
+    name: welampiot
+  datasource:
+#    driver-class-name: com.mysql.jdbc.Driver
+    url: jdbc:mysql://139.196.213.241:3306/welampiot?characterEncoding=utf-8&useSSL=false
+    username: welampiot
+    password: welampiot@2023
+    initialSize: 5
+    minIdle: 5
+    maxActive: 100
+    maxWait: 60000
+    #数据库连接中数据源类型
+    type: com.alibaba.druid.pool.DruidDataSource
+#  jackson:
+#    serialization:
+#      write-null-map-values: true
+#  gson:
+#    serialize-nulls: true
+mybatis:
+  mapper-locations: classpath:/mapper/*.xml
+  check-config-location: true
+  type-aliases-package: com.welampiot
+  configuration:
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+debug: true
+
+logging:
+  file:
+    path: /logs/cis
+  level:
+      root: info
+  config: classpath:logback.xml