Maven 多profile及指定編譯問題的解決
Maven 多profile及指定編譯
要點(diǎn)
項(xiàng)目A依賴項(xiàng)目B,項(xiàng)目A、B都有對應(yīng)的多個(gè)profile,通過mvn –P參數(shù)指定profile,只對A生效,對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不會被執(zhí)行。
實(shí)例
項(xiàng)目A 定義2個(gè)profile(aprofile、bprofile), 項(xiàng)目B定義2個(gè)對應(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指定對應(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)的,插件會在編譯時(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自動切換環(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動態(tài)選擇配置文件詳解
- Maven profile實(shí)現(xiàn)不同環(huán)境的配置管理實(shí)踐
- maven中profile的使用
相關(guān)文章
java同步器AQS架構(gòu)AbstractQueuedSynchronizer原理解析下
這篇文章主要為大家介紹了java同步器AQS架構(gòu)AbstractQueuedSynchronizer原理解析下,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-03-03JavaMail實(shí)現(xiàn)帶附件的郵件發(fā)送
這篇文章主要為大家詳細(xì)介紹了JavaMail實(shí)現(xiàn)帶附件的郵件發(fā)送,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08Spring Boot熱加載jar實(shí)現(xiàn)動態(tài)插件的思路
本文主要介紹在 Spring Boot 工程中熱加載 jar 包并注冊成為 Bean 對象的一種實(shí)現(xiàn)思路,在動態(tài)擴(kuò)展功能的同時(shí)支持在插件中注入主程序的 Bean 實(shí)現(xiàn)功能更強(qiáng)大的插件2021-10-10Spring實(shí)戰(zhàn)之讓Bean獲取Spring容器操作示例
這篇文章主要介紹了Spring實(shí)戰(zhàn)之讓Bean獲取Spring容器操作,結(jié)合實(shí)例形式分析了Bean獲取Spring容器的相關(guān)原理、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下2019-11-11@NotEmpty、@NotBlank、@NotNull的區(qū)別
這篇文章主要介紹了@NotEmpty、@NotBlank、@NotNull的區(qū)別,需要的朋友可以參考下2016-09-09SpringBoot修改子模塊Module的jdk版本的方法 附修改原因
這篇文章主要介紹了SpringBoot修改子模塊Module的jdk版本的方法 附修改原因,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04解決java.util.NoSuchElementException異常的問題
這篇文章主要介紹了解決java.util.NoSuchElementException異常的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09淺析非對稱加密在接口參數(shù)中的實(shí)現(xiàn)
接口層做數(shù)據(jù)加密應(yīng)該算是老生常談的一件事了,業(yè)界用的比較多的,不外乎是對稱加密,非對稱加密以及兩者的結(jié)合。本文就來聊聊非對稱加密在接口參數(shù)中的實(shí)現(xiàn),希望對大家有所幫助2023-02-02