【问题标题】:maven-enforcer-plugin - where to configure in Mavenmaven-enforcer-plugin - 在 Maven 中配置的位置
【发布时间】:2014-09-17 19:53:08
【问题描述】:

我需要在哪里配置这个插件。

是否需要进入settings.xml级别或者每个项目或子项目的pom.xml文件级别?

【问题讨论】:

    标签: xml maven settings release maven-release-plugin


    【解决方案1】:

    这完全取决于你想应用你的实施者规则的项目/模块。

    E.g. 
    Parent -- pom.xml
    |
    |----module 1-------> pom.xml
    |
    |----module 2-------> pom.xml
    

    如果您想在子模块 2 上应用您的规则 - 添加模块 2 的 pom.xml。

    如果您想让您的插件对所有模块可见,请将其添加到父项目的 pom.xml 中。

    如果您想让您的插件对您的环境/组织/公司中的所有项目可见,请为您的环境/组织/公司创建一个 bom(材料清单)。将你的插件添加到 bom.将 bom 发布到存储库并在您的项目中将其配置为父级。

    【讨论】:

    • 谢谢,我尝试将代码放在 ~/.m2 的 settings.xml 中,但即使 pom 文件中有 -SNAPSHOT 条目(在项目的各个级别),它也不会出错。我想知道我是否必须将代码放在每个 pom 中。
    • 我还没有看到 settings.xml 文件中配置的插件。请参阅链接 - maven.40175.n5.nabble.com/…
    【解决方案2】:

    你必须像这样在通常的地方配置maven-enforcer-plugin

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
              <execution>
                <id>enforce-maven</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <configuration>
                  <rules>
                    <requireSameVersions>
                      <plugins>
                        <plugin>org.apache.maven.plugins:maven-surefire-plugin</plugin>
                        <plugin>org.apache.maven.plugins:maven-failsafe-plugin</plugin>
                        <plugin>org.apache.maven.plugins:maven-surefire-report-plugin</plugin>
                      </plugins>
                    </requireSameVersions>
                    <requireMavenVersion>
                      <version>${maven.version}</version>
                    </requireMavenVersion>
                  </rules>    
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    

    【讨论】:

    • 谢谢。但是,我的问题是把上面的代码放在哪里。在 settings.xml 或 pom.xml 中(根、父、模块 pom)?
    • 其他说明,如果我将上面的代码放在 ~/.m2 或 $M2_HOME/conf/settings.xml 的 settings.xml 中,它会将 maven-enforcer-plugin 的效果级联到任何项目/子项目(模块/子项目)?谢谢。
    • 如果您阅读了我的答案并查看了我给定的链接,您应该知道答案是什么。把它放在绒球里。 settings.xml 不可能是因为不可能在设置中或在 settings.xml 中的配置文件中有构建部分
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    • 2023-04-07
    • 2011-01-12
    相关资源
    最近更新 更多