記錄一次詭異的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

相關文章
相關標籤/搜索