Maven 多profile及指定編譯問題的解決
Maven 多profile及指定編譯
要點(diǎn)
項(xiàng)目A依賴項(xiàng)目B,項(xiàng)目A、B都有對(duì)應(yīng)的多個(gè)profile,通過mvn –P參數(shù)指定profile,只對(duì)A生效,對(duì)B不生效
項(xiàng)目A、B模塊位于同一父項(xiàng)目,父項(xiàng)目構(gòu)建時(shí)指定profile,可以傳給A,B項(xiàng)目,A、B都使用同一指定的profile。
也可在父項(xiàng)目中定義屬性,激活子項(xiàng)目profile,意即父項(xiàng)目 profile屬性可傳給各個(gè)子項(xiàng)目。
項(xiàng)目中定義的profile, 若<activeProfileDefault>設(shè)置為false,則不指定profile的情況下,該profil不會(huì)被執(zhí)行。
實(shí)例
項(xiàng)目A 定義2個(gè)profile(aprofile、bprofile), 項(xiàng)目B定義2個(gè)對(duì)應(yīng)的profile(aprofile、bprofile),則可將項(xiàng)目A、B中的aprofile激活方式設(shè)置為:
<activeProfileDefault>true</activeProfileDefault>
bprofile profile激活方式設(shè)置為:
<activation> <property> <name>bprofile</name> </property> </activation>
編譯項(xiàng)目A時(shí)使用參數(shù)可編譯bprofile版本:
mvn clean install -Dbprofile
編譯項(xiàng)目A時(shí)不帶參數(shù)可編譯aprofile版本:
mvn clean install
Maven 指定編譯版本
javac
先從javac的編譯選項(xiàng)-source,-target說起:
- -
source:指定使用什么版本的JDK語法編譯源代碼。java語法總是向后兼容的,為何需要設(shè)置呢?不曉滴 - -
target:指定生成特定于某個(gè)JDK版本的class文件。高版本的class文件不被低版本支持,因此需要該項(xiàng)。注意,最好設(shè)置-bootclasspath指定對(duì)應(yīng)JDK版本的boot classes文件,否則即使設(shè)置了-target也不能在指定版本上運(yùn)行class文件
一般情況下,-target與-source設(shè)置一致,可以不用設(shè)置-target,但最好設(shè)置它。
maven
maven中可以指定JDK編譯版本,還需要確定一下IDE中JDK的使用版本。
在最新的maven中,默認(rèn)編譯版本為1.6,所以需要自己設(shè)置為指定版本。
設(shè)置有兩種方式:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
或
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
兩種一致,都是使用maven-compiler-plugin實(shí)現(xiàn)的,插件會(huì)在編譯時(shí)添加source,target選項(xiàng)。通過插件可以配置更多的選項(xiàng)。
在Java 9后,新增了選項(xiàng)release,同時(shí)指定編譯和輸出時(shí)的JDK版本。也能配置插件,但這里僅給出方便的方式:
<properties>
<maven.compiler.release>9</maven.compiler.release>
</properties>
在spring boot中,有獨(dú)屬于它自己的配置方式,它也是通過插件實(shí)現(xiàn)的(spring boot項(xiàng)目默認(rèn)添加了):
<properties>
<java.version>1.8</java.version>
</properties>
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- maven profile自動(dòng)切換環(huán)境參數(shù)的2種方法詳解
- 使用maven profile指定配置文件打包適用多環(huán)境的方法
- Maven管理SpringBoot Profile詳解
- 詳解Maven profile配置管理及激活profile的幾種方式
- maven的pom.xml中profiles的作用詳解
- maven多profile 打包下 -P參和-D參數(shù)的實(shí)現(xiàn)
- 詳解maven中profiles使用實(shí)現(xiàn)
- maven profile實(shí)現(xiàn)多環(huán)境配置的示例
- maven profile動(dòng)態(tài)選擇配置文件詳解
- Maven profile實(shí)現(xiàn)不同環(huán)境的配置管理實(shí)踐
- maven中profile的使用
相關(guān)文章
java實(shí)現(xiàn)讀取txt文件并以在每行以空格取數(shù)據(jù)
今天小編就為大家分享一篇java實(shí)現(xiàn)讀取txt文件并以在每行以空格取數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07
Java this super代碼實(shí)例及使用方法總結(jié)
這篇文章主要介紹了Java this super代碼實(shí)例及使用方法總結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
基于java socket實(shí)現(xiàn) 聊天小程序
這篇文章主要介紹了基于java socket實(shí)現(xiàn) 聊天小程序,代碼分為服務(wù)器和客戶端,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
screw?Maven插件方式運(yùn)行時(shí)在編譯打包時(shí)跳過執(zhí)行的問題解決方法
這篇文章主要介紹了screw?Maven插件方式運(yùn)行時(shí)在編譯打包時(shí)跳過執(zhí)行的問題解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03

