亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

Maven中的scope總結(jié)

Maven中的scope主要有以下6種

接下來分別介紹下這幾種scope:

  • compile

不聲明scope元素的情況下的默認值;compile表示被依賴包需要參與當前項目的編譯,包括后續(xù)的測試,運行周期也參與其中,是一個比較強的依賴;打包的時候通常需要包含進去。

  • provided

provided 類型的scope只會在項目的編譯、測試階段起作用;可以認為在目標容器中已經(jīng)提供了這個依賴,無需在提供,但是在編寫代碼或者編譯時可能會用到這個依賴;依賴不會被打入到項目jar包中。

說到provided,這里就要說到<dependency>下的子標簽<optional> ,如果一個依賴的<optional> 設(shè)置為true,則該依賴在打包的時候不會被打進jar包,同時不會通過依賴傳遞傳遞到依賴該項目的工程;例如:x

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

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

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

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

  • runtime

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

  • test

在一般的編譯和運行時都不需要,它們只有在測試編譯和測試運行階段可用,不會被打包到項目jar包中,同時如果項目A依賴于項目B,項目B中的test作用域下的依賴不會被繼承。

  • system

表示使用本地系統(tǒng)路徑下的jar包,需要和一個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 項目的POM文件中,我們可以通過在POM文件中繼承 Spring-boot-starter-parent來引

用Srping boot默認依賴的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>

但是,通過上面的parent繼承的方法,只能繼承一個 spring-boot-start-parent。實際開發(fā)中,用戶很可能需要繼承自己公司的標準parent配置,這個時候可以使用 scope=import 來實現(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>

通過上面方式,就可以獲取spring-boot-dependencies.2.0.1.BUILD-SNAPSHOT.pom文件中dependencyManagement配置的jar包依賴。如果要繼承多個,可以在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>默認值,表示當前依賴包要參與當前項目的編譯后續(xù)測試運行時打包
<scope>provided</scope>當前包只在編譯和測試的時候使用,而不再后續(xù)的運行和打包的時候不會打包進來
<scope>test</scope>表示當前依賴包只參與測試工作
<scope>runtime</scope>表示當前依賴包只參與運行周期,其他跳過
<scope>system</scope>從參與度和provided一致,不過被依賴項不會從maven遠程倉庫下載,而是從本地的系統(tǒng)拿。需要systemPath屬性來定義路徑

解決maven項目中無法打包生成空文件夾的問題

            <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>

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

相關(guān)文章

最新評論