栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

深入浅析maven profile的激活

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

深入浅析maven profile的激活

说起maven的profile,相信大家都不会陌生,可以根据不同的情况激活不同的profile,达到灵活配置的目的。这里给大家简单介绍一下maven profile激活的相关知识。

怎么知道哪些profile激活了

运行mvn help:active-profiles命令即可。例如有如下的pom文件

    
 
     bar
     
  true
     
 
 
     foo
 
    

运行结果为:

The following profiles are active:

 - bar (source: org.example:maven:1.0-SNAPSHOT)
activeByDefault VS activeProfiles

activeProfiles元素出现在settings文件中,它指定的profile一定会激活。
例如在settings文件中有如下内容:

	
		
			foo
		
		
			dev
		
	
	
		dev
	

运行mvn help:active-profiles结果为:

The following profiles are active:

 - dev (source: external)

运行mvn -P foo help:active-profiles结果为:

The following profiles are active:

 - foo (source: external)
 - dev (source: external)

而当一个标记了activeByDefault的profile出现在pom中时,如果同一个pom文件中其他profile没有激活,则该profile激活,其他profile有激活的,则该profile不激活。例如在pom文件中有如下内容:

    
 
     bar
     
  true
     
 
 
     foo
 
    

运行mvn help:active-profiles结果为:

The following profiles are active:

 - bar (source: org.example:maven:1.0-SNAPSHOT)

运行mvn -P foo help:active-profiles结果为:


 - foo (source: org.example:maven:1.0-SNAPSHOT)

当然了,activeByDefault也能出现在settings文件中,但是官方文档也没支持这种情况下,其表现形式是怎样的。

properties激活profile

我们已经知道,pom文件中的properties是无法激活它自己的profile的(请参阅 https://www.imooc.com/article/299915 ),然而可以在settings文件中的profile里设置properties,进而激活pom中的profile。
例如在settings文件中这样设置:

    
 
     dev
     
  xyz
     
 
    

	
		dev
	

在pom中这样写:

   

    foo
    
 
     abc
     xyz
 
    

   

运行mvn help:active-profiles,可以看到,foo这个profile被激活了

The following profiles are active:

 - dev (source: external)
 - foo (source: org.example:maven:1.0-SNAPSHOT)
转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号