3

私は最近、Maven Enforcer Pluginを使用して、すべての POM がプロパティを定義することを義務付けましたfoo.bar。私はこのステートメントを会社の POM に入れ、それが私の子プロジェクトに適用されると想定しました。

がっかりしたことに (驚きではありませんが)、この規則は私の会社の POM にも適用されていました。その結果、プレースホルダーfoo.barプロパティを忠実に定義し、完了したと思いました。

残念ながら、すべての子プロジェクトはこのプロパティを継承するため、エンフォーサー テストに合格します。子供たちがこのプロパティを明示的に定義したのか、単に意味のない値を継承したのかを判断できないままです。誰でも次のいずれかの方法を提案できますか:

  • この (特定の) ルールが私の会社の POM に適用されないようにします。また

  • プレースホルダー プロパティが子プロジェクトに継承されないようにします。また

  • 私の問題を別の方法で解決しますか?

参考までに、私のエンフォーサ ルールの定義を以下に示します。このスニペットは、私の会社の POM からのものです。

<!-- Enforce good behaviour in child POMs -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.2</version>
  <executions>
    <execution>
      <id>enforce-good-behaviour</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireProperty>
            <property>foo.bar</property>
            <message>NAUGHTY!</message>
            <regex>.+</regex>
            <regexMessage>The property must contain at least one character.</regexMessage>
          </requireProperty>
        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>

私の目標は、このプロパティ値を SCM タグ付け命令の一部として自動的に使用することでした。私の会社の POM には、子プロジェクトの適切なタグ付けスキームを定義する次のスニペットがあります。

<!-- Ensure we use a consistent tagging scheme for releases -->
<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <configuration>
    <tagNameFormat>a.b.c.${foo.bar}</tagNameFormat>
    <useReleaseProfile>false</useReleaseProfile>
  </configuration>
</plugin>
4

2 に答える 2

3

これとまったく同じジレンマがありました。これが私がそれを解決した方法です。

企業のPOMに、次のようなプロファイルを追加しました。

    <profile>
    <!-- When we are building the corporate base projects we don't want 
         to require that all of the properties that should be provided by 
         child projects (inheriters) are defined. So we activate this 
         profile when building the corporate projects to bypass anything 
         that only applies to children (the leaf projects). 
         Add "-Dcorporate.build=true" on the maven cmd line when building
         and releasing the corporate POMs to accomplish this. -->
        <id>corporate-pom-build</id>
        <activation>
            <property>
                <name>corporate.build</name>
                <value>true</value>
            </property>
        </activation>
        <properties>
            <enforcer.skip>true</enforcer.skip>
            <remoteresources.skip>true</remoteresources.skip>
            <assembly.skipAssembly>true</assembly.skipAssembly>
        </properties>
    </profile>

次に、コメントにあるように、私は企業のPOMを構築します

mvn -Dcorporate.build=true clean deploy

スキップしたい他のこともそのプロファイルに入れることができます。チャームのように機能します。

于 2013-02-07T14:44:57.500 に答える
0

extra-enforcer-rulesrequirePropertyDivergesルールを使用すると、親 POM で定義されているプロパティが子 POM でオーバーライドされていることを確認できます。

あなたのユースケースでは、設定は次のようになります(テストしていません):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>1.2</version>
  <executions>
    <execution>
      <id>enforce-property-overridden-in-child</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requirePropertyDiverges>
            <property>foo.bar</property>
          </requirePropertyDiverges>
        </rules>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>extra-enforcer-rules</artifactId>
      <version>1.0-alpha-5</version>
    </dependency>
  </dependencies>
</plugin>
于 2013-06-25T10:59:40.093 に答える