记录一次诡异的Maven Profile不生效的问题

记录一次诡异的Maven Profile不生效的问题

现象

maven 打包以后,复制的 profile对应的resource文件老是不正确的。
即使是加了spring

mvn clean package -P test

,profile每次都是复制了 dev这个profile,非常奇怪。apache

诊断

mvn resource:resource

用该命令,能够快速测试复制resources配置文件是否正确。
可是target 文件夹内依然是dev的。maven

Apache Maven Help Plugin

mvn help:active-profiles

输出相似:测试

profile dev (external)

这我就忽然想到,external 是否是外部的,也就是与本项目无关的。url

结果打开 maven的 settings.xml文件,划到下面发现了下面的内容:code

<profile>  
      <id>dev</id>  
      <repositories>            
          <repository>    
          <id>spring-plugin</id>    
          <name>spring-plugin</name>    
          <url>http://repo.spring.io/plugins-release/</url>    
          <releases>    
            <enabled>true</enabled>    
          </releases>    
          <snapshots>    
            <enabled>false</enabled>    
          </snapshots>    
        </repository> 
        
      </repositories>    
      <pluginRepositories>      
    <pluginRepository>    
          <id>spring-plugin</id>    
          <name>spring-plugin</name>    
          <url>http://repo.spring.io/plugins-release/</url>    
          <releases>    
            <enabled>true</enabled>    
          </releases>    
          <snapshots>    
            <enabled>false</enabled>    
          </snapshots>        
        </pluginRepository>    
      </pluginRepositories>       
    </profile> 

....
     <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>

总结

而后恍然大雾,原来maven用了这么多年,依旧没有完全弄明白。。这是处处复制maven settings配置,而不清楚或者误解其做用致使的隐患啊。
这里的profile dev但是全局激活的啊,幸亏生产环境的 没有使用maven profile。
否则 不管怎么写命令,dev永远是激活的。xml

相关文章
相关标签/搜索