記錄一次詭異的Maven Profile不生效的問題
現象
maven 打包之后,復制的 profile對應的resource文件總是不正確的。
即便是加了
mvn clean package -P test
,profile每次都是復制了 dev這個profile,很是奇怪。
診斷
mvn resource:resource
用該命令,可以快速測試復制resources配置文件是否正確。
但是target 文件夾內依然是dev的。
Apache Maven Help Plugin
mvn help:active-profiles
輸出類似:
profile dev (external)
這我就突然想到,external 是不是外部的,也就是與本項目無關的。
結果打開 maven的 settings.xml文件,划到下面發現了下面的內容:
<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永遠是激活的。
