欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用Maven中的scope總結(jié)

 更新時(shí)間:2022年06月15日 09:43:53   作者:野生開(kāi)發(fā)者  
這篇文章主要介紹了使用Maven中的scope總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Maven中的scope總結(jié)

Maven中的scope主要有以下6種

接下來(lái)分別介紹下這幾種scope:

  • compile

不聲明scope元素的情況下的默認(rèn)值;compile表示被依賴包需要參與當(dāng)前項(xiàng)目的編譯,包括后續(xù)的測(cè)試,運(yùn)行周期也參與其中,是一個(gè)比較強(qiáng)的依賴;打包的時(shí)候通常需要包含進(jìn)去。

  • provided

provided 類型的scope只會(huì)在項(xiàng)目的編譯、測(cè)試階段起作用;可以認(rèn)為在目標(biāo)容器中已經(jīng)提供了這個(gè)依賴,無(wú)需在提供,但是在編寫代碼或者編譯時(shí)可能會(huì)用到這個(gè)依賴;依賴不會(huì)被打入到項(xiàng)目jar包中。

說(shuō)到provided,這里就要說(shuō)到<dependency>下的子標(biāo)簽<optional> ,如果一個(gè)依賴的<optional> 設(shè)置為true,則該依賴在打包的時(shí)候不會(huì)被打進(jìn)jar包,同時(shí)不會(huì)通過(guò)依賴傳遞傳遞到依賴該項(xiàng)目的工程;例如:x

依賴B,B由依賴于A(x->B->A),則A中設(shè)置<optional> 為true的依賴不會(huì)被傳遞到x中。

這兩者的區(qū)別在于:

1、<optional>為true 表示某個(gè)依賴可選,該依賴是否使用都不會(huì)影響服務(wù)運(yùn)行;

2、provided的<scope>在目標(biāo)容器中已經(jīng)提供了這個(gè)依賴,無(wú)需在提供

  • runtime

runtime與compile比較相似,區(qū)別在于runtime 跳過(guò)了編譯階段,打包的時(shí)候通常需要包含進(jìn)去。

  • test

在一般的編譯和運(yùn)行時(shí)都不需要,它們只有在測(cè)試編譯和測(cè)試運(yùn)行階段可用,不會(huì)被打包到項(xiàng)目jar包中,同時(shí)如果項(xiàng)目A依賴于項(xiàng)目B,項(xiàng)目B中的test作用域下的依賴不會(huì)被繼承。

  • system

表示使用本地系統(tǒng)路徑下的jar包,需要和一個(gè)systemPath一起使用,如下:

<!--引用-->
?? ??? ?<dependency>
?? ??? ??? ?<groupId>xxxx</groupId>
?? ??? ??? ?<artifactId>xxx</artifactId>
?? ??? ??? ?<systemPath>${basedir}/lib/xxxxx.jar</systemPath>
?? ??? ??? ?<scope>system</scope>
?? ??? ??? ?<version>1.4.12</version>
?? ??? ?</dependency>
  • import

import 只能在pom文件的<dependencyManagement>中使用,從而引入其他的pom文件中引入依賴,如:在Spring boot 項(xiàng)目的POM文件中,我們可以通過(guò)在POM文件中繼承 Spring-boot-starter-parent來(lái)引

用Srping boot默認(rèn)依賴的jar包,如下:

<!-- Inherit defaults from Spring Boot -->
<parent>
?? ?<groupId>org.springframework.boot</groupId>
?? ?<artifactId>spring-boot-starter-parent</artifactId>
?? ?<version>2.0.1.BUILD-SNAPSHOT</version>
</parent>

但是,通過(guò)上面的parent繼承的方法,只能繼承一個(gè) spring-boot-start-parent。實(shí)際開(kāi)發(fā)中,用戶很可能需要繼承自己公司的標(biāo)準(zhǔn)parent配置,這個(gè)時(shí)候可以使用 scope=import 來(lái)實(shí)現(xiàn)多繼承。代碼如下:

?? ? <dependencyManagement>
?? ? ? ? <dependencies>
?? ? ? ? ? ? <dependency>
?? ? ? ? ? ? ? ? <!-- Import dependency management from Spring Boot -->
?? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId>
?? ? ? ? ? ? ? ? <artifactId>spring-boot-dependencies</artifactId>
?? ? ? ? ? ? ? ? <version>2.0.1.BUILD-SNAPSHOT</version>
?? ? ? ? ? ? ? ? <type>pom</type>
?? ? ? ? ? ? ? ? <scope>import</scope>
?? ? ? ? ? ?</dependency>
?? ? ? ?</dependencies>
?? ?</dependencyManagement>

通過(guò)上面方式,就可以獲取spring-boot-dependencies.2.0.1.BUILD-SNAPSHOT.pom文件中dependencyManagement配置的jar包依賴。如果要繼承多個(gè),可以在dependencyManagement中添加,如:

?? ? <dependencyManagement>
?? ? ? ? <dependencies>
?? ? ? ? ? ? <!-- Override Spring Data release train provided by Spring Boot -->
?? ? ? ? ? ? <dependency>
?? ? ? ? ? ? ? ? <groupId>org.springframework.data</groupId>
?? ? ? ? ? ? ? ? <artifactId>spring-data-releasetrain</artifactId>
?? ? ? ? ? ? ? ? <version>Fowler-SR2</version>
?? ? ? ? ? ? ? ? <type>pom</type>
?? ? ? ? ? ? ? ? <scope>import</scope>
?? ? ? ? ? ?</dependency>
?? ? ? ? ? ?<dependency>
?? ? ? ? ? ? ? ?<groupId>org.springframework.boot</groupId>
?? ? ? ? ? ? ? ?<artifactId>spring-boot-dependencies</artifactId>
?? ? ? ? ? ? ? ?<version>2.0.1.BUILD-SNAPSHOT</version>
?? ? ? ? ? ? ? ?<type>pom</type>
?? ? ? ? ? ? ? ?<scope>import</scope>
?? ? ? ? ? ?</dependency>
?? ? ? ?</dependencies>
?? ?</dependencyManagement>

Maven中<scope>參數(shù)</scope>配置

參數(shù)名稱具體功能
<scope>compile</scope>默認(rèn)值,表示當(dāng)前依賴包要參與當(dāng)前項(xiàng)目的編譯后續(xù)測(cè)試運(yùn)行時(shí)打包
<scope>provided</scope>當(dāng)前包只在編譯和測(cè)試的時(shí)候使用,而不再后續(xù)的運(yùn)行和打包的時(shí)候不會(huì)打包進(jìn)來(lái)
<scope>test</scope>表示當(dāng)前依賴包只參與測(cè)試工作
<scope>runtime</scope>表示當(dāng)前依賴包只參與運(yùn)行周期,其他跳過(guò)
<scope>system</scope>從參與度和provided一致,不過(guò)被依賴項(xiàng)不會(huì)從maven遠(yuǎn)程倉(cāng)庫(kù)下載,而是從本地的系統(tǒng)拿。需要systemPath屬性來(lái)定義路徑

解決maven項(xiàng)目中無(wú)法打包生成空文件夾的問(wèn)題

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <!-- Run shade goal on package phase -->
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <exclude>org.apache.flink:force-shading</exclude>
                                    <exclude>com.google.code.findbugs:jsr305</exclude>
                                    <exclude>org.slf4j:*</exclude>
                                    <exclude>org.apache.logging.log4j:*</exclude>
                                </excludes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <!-- Do not copy the signatures in the META-INF folder.
                                    Otherwise, this might cause SecurityExceptions when using the JAR. -->
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.lkr.flink.StreamingJob</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。 

相關(guān)文章

最新評(píng)論