【问题标题】:maven3 detect maven version for plugin - fails to activate other default profilesmaven3 检测插件的 maven 版本 - 无法激活其他默认配置文件
【发布时间】:2012-06-15 14:36:52
【问题描述】:

我需要检测用户是否在我的父 pom 中使用 mvn2 或 mvn3 以加载正确的插件版本。我遵循了这里的建议:http://maven.apache.org/plugins/maven-site-plugin/maven-3.html#Using_maven-site-plugin_2.x_with_Maven_2_and_maven-site-plugin_3.x_with_Maven_3

检测机制运行良好 - 但是,我的其他激活 ByDefaul 的配置文件不再被拾取。

超级 pom 如下所示:

<profile>
    <id>profile-1</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
</profile>
<profile>
    <id>profile-2</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
</profile>
   <profile>
      <id>maven-3</id>
      <activation>
         <file>
         <!--  This employs that the basedir expression is only recognized by Maven 3.x (see MNG-2363) -->
            <exists>${basedir}</exists>
        </file> 
      </activation>     
      <build>
         <pluginManagement>
            <plugins>
               <plugin>
                  <groupId>com.company.plugins</groupId>
                      <artifactId>my-super-plugin</artifactId>
                      <version>1.0-123</version>
                    </plugin>
            </plugins>
         </pluginManagement>
      </build>
   </profile>
 </profiles>

当我使用 mvn3 运行 mvn help:active-profiles --> 仅列出 maven-3 配置文件。如果我使用 mvn2,profile-1 会正确列出。

*编辑 * :事实证明,它实际上在这里有很好的记录:http://maven.apache.org/guides/introduction/introduction-to-profiles.html

除非使用上述方法之一激活同一 POM 中的另一个配置文件,否则此配置文件将自动对所有构建有效。当在命令行或通过其激活配置激活 POM 中的配置文件时,默认情况下处于活动状态的所有配置文件都会自动停用。

我现在的问题是:如果使用-P profile2,您建议默认激活profile1,激活profile 2,如果使用maven3,则激活maven-3 profile?

【问题讨论】:

    标签: maven maven-2 maven-3


    【解决方案1】:

    到目前为止,我还没有找到比这更好的东西:

    <activation>
        <property>
            <name>!dummy</name>
        </property>
    </activation>
    

    dummy 是某种愚蠢的变量名,您肯定不会使用。

    【讨论】:

    • 嗯 - 这对我最初的请求有用 - 我更新了我的原始评论以完全描述我的环境。我需要:默认情况下 profile1,如果指定 profile2 并且 maven-3 自动拾取....
    • 所以我不再理解你了。您能否再次描述一下这些场景以及哪些配置文件处于活动状态?
    • 我有 2 个部署配置文件:通过 http 部署和通过 ssh 部署。默认情况下,http 部署应该是活动的。在这 2 个配置文件之上,我有一个 maven-3 配置文件,在使用 maven-3 时应该被激活。有意义吗?
    • 是的,我想我明白了。但是我无法帮助你,我真的不确定你是否可以使用 Maven 仅使用普通配置文件来做到这一点。当然可以通过使用一些激活 SSH 部署的属性来启用/禁用正确的配置文件,但是如果有人不知道它并使用配置文件(使用-P 开关),那么所有这些技巧都会停止工作。
    猜你喜欢
    • 2019-05-17
    • 1970-01-01
    • 2017-02-26
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 2014-10-29
    • 1970-01-01
    相关资源
    最近更新 更多