引入說的是“運(yùn)行時(shí)”而非編譯期
如果編譯期用到了依賴的具體類舞萄,則需要提供一個(gè)編譯期compile的依賴
重點(diǎn)來了倒脓,如何實(shí)現(xiàn)不同環(huán)境引入不同的依賴?
<profiles>
? ? ? ? <profile>
? ? ? ? ? ? <id>dev</id>
? ? ? ? ? ? <!-- 默認(rèn)激活 dev 環(huán)境 -->
? ? ? ? ? ? <activation>
? ? ? ? ? ? ? ? <activeByDefault>true</activeByDefault>
? ? ? ? ? ? </activation>
? ? ? ? ? ? <properties>
? ? ? ? ? ? ? ? <profiles.active>dev</profiles.active>
? ? ? ? ? ? </properties>
? ? ? ? ? ? <dependencies>
? ? ? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? ? ? <groupId>xx</groupId>
? ? ? ? ? ? ? ? ? ? <artifactId>xx</artifactId>
? ? ? ? ? ? ? ? ? ? <version>v1</version>
? ? ? ? ? ? ? ? </dependency>
? ? ? ? ? ? </dependencies>
? ? ? ? </profile>
? ? ? ? <profile>
? ? ? ? ? ? <id>test</id>
? ? ? ? ? ? <properties>
? ? ? ? ? ? ? ? <profiles.active>test</profiles.active>
? ? ? ? ? ? </properties>
? ? ? ? ? ? <dependencies>
? ? ? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? ? ? <groupId>xx</groupId>
? ? ? ? ? ? ? ? ? ? <artifactId>xx</artifactId>
? ? ? ? ? ? ? ? ? ? <version>v1</version>
? ? ? ? ? ? ? ? </dependency>
? ? ? ? ? ? </dependencies>
? ? ? ? </profile>
? ? ? ? <profile>
? ? ? ? ? ? <id>uat</id>
? ? ? ? ? ? <properties>
? ? ? ? ? ? ? ? <profiles.active>uat</profiles.active>
? ? ? ? ? ? </properties>
? ? ? ? ? ? <dependencies>
? ? ? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? ? ? <groupId>xx</groupId>
? ? ? ? ? ? ? ? ? ? <artifactId>xx</artifactId>
? ? ? ? ? ? ? ? ? ? <version>v1</version>
? ? ? ? ? ? ? ? </dependency>
? ? ? ? ? ? </dependencies>
? ? ? ? </profile>
? ? ? ? <profile>
? ? ? ? ? ? <id>deploy<!--表示線上--></id>
? ? ? ? ? ? <properties>
? ? ? ? ? ? ? ? <profiles.active>deploy</profiles.active>
? ? ? ? ? ? </properties>
? ? ? ? ? ? <dependencies>
? ? ? ? ? ? ? ? <dependency>
? ? ? ? ? ? ? ? ? ? <groupId>xx</groupId>
? ? ? ? ? ? ? ? ? ? <artifactId>xx</artifactId>
? ? ? ? ? ? ? ? ? ? <version>v2</version>
? ? ? ? ? ? ? ? </dependency>
? ? ? ? ? ? </dependencies>
? ? ? ? </profile>
? ? </profiles>
可以看到,這樣這樣再那樣就可以了
這樣就實(shí)現(xiàn)了下線環(huán)境
注意:底層是通過maven打包時(shí)候的命令來實(shí)現(xiàn)的
mvn clean package -U -Denv=dev -Dmaven.test.skip=true -f ./pom.xml -P ${這里就是profile.active的值}
所以選擇哪個(gè)依賴版本進(jìn)行打包是maven package的時(shí)候決定的