zoukankan      html  css  js  c++  java
  • 记录一次诡异的Maven Profile不生效的问题

    记录一次诡异的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永远是激活的。

  • 相关阅读:
    标识符
    注释
    关键字
    第一个JAVA程序
    JAVA运行机制
    每个程序员都应该知道的延迟数
    构建WebDriverAgent时报错“xxx: no identity found Command CodeSign failed with a nonzero exit code”解决办法
    执行 sh ./Scripts/bootstrap.sh -d 时提示“xcrun: error: unable to find utility “simctl”, not a developer tool or in PATH ”错误解决办法
    stf ios版本部署
    centos 7安装一机多控stf客户端
  • 原文地址:https://www.cnblogs.com/slankka/p/10092628.html
Copyright © 2011-2022 走看看