僅作爲項目模板,備忘,避免重複採坑,不解說。
主要包含:
1.項目依賴到maven私服相關配置,除此之外還需要設置maven配置文件setting.xml
2.編譯項目使用jdk1.7
3.打包項目去除依賴包,並生成lib文件。
4.打包時去除配置文件和日誌文件,後臺微服務的服務器配置文件和日誌配置文件統一從遠程拉取。
5.項目依賴到maven私服時,將代碼也放上去。
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.19.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>dubbo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
</dependencies>
<!-- maven私服 -->
<distributionManagement>
<repository>
<id>maven-test-releases</id>
<name>maven-test-releases</name>
<url>http://127.0.0.1:8081/repository/maven-test-release/</url>
</repository>
<snapshotRepository>
<id>maven-test-snapshot</id>
<name>maven-test-snapshot</name>
<url>http://127.0.0.1:8081/repository/maven-test-snapshot/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<!-- 使用java jdk1.7編譯 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- 打包jar時,去除依賴,並生成lib -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/main/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteIfNewer>true</overWriteIfNewer>
<overWriteSnapshots>false</overWriteSnapshots>
<excludeArtifactIds>slf4j-log4j12</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<!-- 去除配置文件和日誌文件 -->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>-->
<!-- 後臺微服務的服務器配置文件和日誌配置文件統一從遠程拉取,所以打包的時候要排除掉 --><!--
<exclude>application.properties</exclude>
<exclude>logback.xml</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>src/main/lib/</classpathPrefix>
<mainClass>com.example.dubbo.DubboApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
-->
<!-- 要將源碼上傳至maven私服,需要加入這個插件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>