1-02举庶、創(chuàng)建統(tǒng)一的依賴管理

溫馨提示
當前 Spring Cloud Alibaba 的 2.1.0.RELEASE 版本基于 Spring Cloud Greenwich 開發(fā)心褐,
Spring Cloud Alibaba 項目都是基于 Spring Cloud蜈七,而 Spring Cloud 項目又是基于 Spring Boot 進行開發(fā)乱凿,并且都是使用 Maven 做項目管理工具蚯撩。在實際開發(fā)中础倍,我們一般都會創(chuàng)建一個依賴管理項目作為 Maven 的 Parent 項目使用,這樣做可以極大的方便我們對 Jar 包版本的統(tǒng)一管理胎挎。

Spring Cloud Alibaba 項目都是基于 Spring Cloud沟启,而 Spring Cloud 項目又是基于 Spring Boot 進行開發(fā)忆家,并且都是使用 Maven 做項目管理工具。在實際開發(fā)中德迹,我們一般都會創(chuàng)建一個依賴管理項目作為 Maven 的 Parent 項目使用芽卿,這樣做可以極大的方便我們對 Jar 包版本的統(tǒng)一管理。

創(chuàng)建依賴管理項目

Spring Boot 版本查詢
Spring Cloud 版本查詢
Spring Cloud Alibaba 版本查詢
Spring Boot胳搞,Spring Cloud卸例,Spring Cloud Alibaba 版本選擇說明以及整理歸納

創(chuàng)建一個工程名為 hello-spring-cloud-alibaba-dependencies 的項目,pom.xml 配置文件如下:

<?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 http://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>2.1.9.RELEASE</version>
    </parent>

    <groupId>com.wj</groupId>
    <artifactId>hello-spring-cloud-alibaba-dependencies</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <name>hello-spring-cloud-alibaba-dependencies</name>
    <inceptionYear>2020-Now</inceptionYear>
    <description>Demo project for Spring Boot</description>

    <packaging>pom</packaging>

    <properties>
        <!-- Environment Settings -->
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Spring Settings -->
        <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
        <spring-cloud-alibaba.version>2.1.0.RELEASE</spring-cloud-alibaba.version>
        <!-- 暫時使用2.1.1.RELEASE會導(dǎo)致啟動不起來肌毅,故先使用2.1.0.RELEASE -->
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Compiler 插件, 設(shè)定 JDK 版本 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>

            <!-- 打包 jar 文件時筷转,配置 manifest 文件,加入 lib 包的 jar 依賴 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <configuration>
                            <archive>
                                <manifest>
                                    <!-- Add directory entries -->
                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- resource -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>

            <!-- install -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
            </plugin>

            <!-- clean -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
            </plugin>

            <!-- ant -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
            </plugin>

            <!-- dependency -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <!-- Java Document Generate -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- YUI Compressor (CSS/JS壓縮) -->
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>yuicompressor-maven-plugin</artifactId>
                    <version>1.5.1</version>
                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>compress</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <jswarn>false</jswarn>
                        <nosuffix>true</nosuffix>
                        <linebreakpos>30000</linebreakpos>
                        <force>true</force>
                        <includes>
                            <include>**/*.js</include>
                            <include>**/*.css</include>
                        </includes>
                        <excludes>
                            <exclude>**/*.min.js</exclude>
                            <exclude>**/*.min.css</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <!-- 資源文件配置 -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

    <repositories>
        <repository>
            <id>aliyun-repos</id>
            <name>Aliyun Repository</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>sonatype-repos</id>
            <name>Sonatype Repository</name>
            <url>https://oss.sonatype.org/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>sonatype-repos-s</id>
            <name>Sonatype Repository</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>aliyun-repos</id>
            <name>Aliyun Repository</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>
  • parent:繼承了 Spring Boot 的 Parent芽腾,表示我們是一個 Spring Boot 工程
  • package:pom旦装,表示該項目僅當做依賴項目,沒有具體的實現(xiàn)代碼
  • spring-cloud-alibaba-dependencies:在 properties 配置中預(yù)定義了版本號為 2.1.1.RELEASE 摊滔,表示我們的 Spring Cloud Alibaba 對應(yīng)的是 Spring Cloud Greenwich 版本
  • build:配置了項目所需的各種插件
  • repositories:配置項目下載依賴時的第三方庫

依賴版本說明

版本說明:截至目前 2020-02-13阴绢,最新版本號為2.1.1.RELEASE

與 Spring Cloud Netflix 的區(qū)別

主要增加了 org.springframework.cloud:spring-cloud-alibaba-dependencies

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市艰躺,隨后出現(xiàn)的幾起案子呻袭,更是在濱河造成了極大的恐慌,老刑警劉巖腺兴,帶你破解...
    沈念sama閱讀 221,695評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件左电,死亡現(xiàn)場離奇詭異,居然都是意外死亡页响,警方通過查閱死者的電腦和手機篓足,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,569評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來闰蚕,“玉大人栈拖,你說我怎么就攤上這事∶欢福” “怎么了涩哟?”我有些...
    開封第一講書人閱讀 168,130評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長盼玄。 經(jīng)常有香客問我贴彼,道長,這世上最難降的妖魔是什么埃儿? 我笑而不...
    開封第一講書人閱讀 59,648評論 1 297
  • 正文 為了忘掉前任器仗,我火速辦了婚禮,結(jié)果婚禮上童番,老公的妹妹穿的比我還像新娘青灼。我一直安慰自己暴心,他們只是感情好,可當我...
    茶點故事閱讀 68,655評論 6 397
  • 文/花漫 我一把揭開白布杂拨。 她就那樣靜靜地躺著专普,像睡著了一般。 火紅的嫁衣襯著肌膚如雪弹沽。 梳的紋絲不亂的頭發(fā)上檀夹,一...
    開封第一講書人閱讀 52,268評論 1 309
  • 那天,我揣著相機與錄音策橘,去河邊找鬼炸渡。 笑死,一個胖子當著我的面吹牛丽已,可吹牛的內(nèi)容都是我干的蚌堵。 我是一名探鬼主播,決...
    沈念sama閱讀 40,835評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼沛婴,長吁一口氣:“原來是場噩夢啊……” “哼吼畏!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起嘁灯,我...
    開封第一講書人閱讀 39,740評論 0 276
  • 序言:老撾萬榮一對情侶失蹤泻蚊,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后丑婿,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體性雄,經(jīng)...
    沈念sama閱讀 46,286評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,375評論 3 340
  • 正文 我和宋清朗相戀三年羹奉,在試婚紗的時候發(fā)現(xiàn)自己被綠了秒旋。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,505評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡诀拭,死狀恐怖迁筛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情炫加,我是刑警寧澤,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布铺然,位于F島的核電站俗孝,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏魄健。R本人自食惡果不足惜赋铝,卻給世界環(huán)境...
    茶點故事閱讀 41,873評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望沽瘦。 院中可真熱鬧革骨,春花似錦农尖、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,357評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至筑凫,卻和暖如春滑沧,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背巍实。 一陣腳步聲響...
    開封第一講書人閱讀 33,466評論 1 272
  • 我被黑心中介騙來泰國打工滓技, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人棚潦。 一個月前我還...
    沈念sama閱讀 48,921評論 3 376
  • 正文 我出身青樓令漂,卻偏偏與公主長得像,于是被迫代替她去往敵國和親丸边。 傳聞我的和親對象是個殘疾皇子叠必,可洞房花燭夜當晚...
    茶點故事閱讀 45,515評論 2 359

推薦閱讀更多精彩內(nèi)容