0

我编写并测试了一个自定义执行器规则,以在各种 Linux 发行版上进行特定于发行版的构建。它使用mvn enforcer:enforce命令以及提供的pom.xml构建片段进行了很好的测试。

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.0-beta-1</version>
    <dependencies>
      <dependency>
        <groupId>org.example</groupId>
        <artifactId>maven-enforcer-rule-redhat6x</artifactId>
        <version>1.0</version>
      </dependency>
    </dependencies>
    <configuration>
      <rules>
        <redhat6x implementation="org.example.enforcer.Redhat6x">
          <compatible>true</compatible>
        </redhat6x>
      </rules>
    </configuration>
    <executions>
      <execution>
        <id>enforce</id>
      </execution>
    </executions>
    <goals>
      <goal>enforce</goal>
    </goals>
  </plugin>
</plugins>

在绞尽脑汁并进行大量实验测试之后,我似乎找不到如何使用此自定义强制执行规则作为配置文件激活选择器。

  <profiles>
    <profile>
      <id>RedHat6x</id>
      <activation>
      <!-- Something goes here, but what?  This doesn't work -->
            <redhat6x implementation="com.cisco.tesdw.enforcer.Redhat6x">
              <compatible>true</compatible>
            </redhat6x>
      </activation>
    </profile>
  </profiles>

配置文件激活使用了一些提示,maven-enforcer-rules详见配置文件简介页面的“我如何知道哪些配置文件在构建期间有效”部分下。即,具有多个字符串值(操作系统名称等)的每个配置文件激活都引用了相应的 maven 强制执行规则。但是,似乎在 pom.xml 中直接包含自定义配置文件激活器并不明显,添加此类可能需要 pom version update

Maven3 也可以以非常灵活的方式进行扩展,是否可以通过 Maven 扩展机制挂钩包含我的强制执行规则?有关于如何包含自定义生命周期参与者的文档;但是,我担心在构建开始时可能已经激活了配置文件。文档很少,但 javadoc 表明它AbstractMavenLifecycleParticipant.afterProjectsRead(MavenSession session)被称为“在MavenProject创建所有实例之后”。这让我怀疑它是否在配置文件激活之前或之后被调用。我怀疑之后,或者如何正确配置MavenProject

有人可以告诉我配置文件激活自定义是否甚至可以远程实现吗?

4

1 回答 1

1

您只需要在配置文件下移动插件配置:

<profiles>
    <profile>
      <id>RedHat6x</id>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>1.0-beta-1</version>
          <dependencies>
            <dependency>
              <groupId>org.example</groupId>
              <artifactId>maven-enforcer-rule-redhat6x</artifactId>
              <version>1.0</version>
            </dependency>
          </dependencies>
          <configuration>
            <rules>
              <redhat6x implementation="org.example.enforcer.Redhat6x">
                <compatible>true</compatible>
              </redhat6x>
            </rules>
          </configuration>
          <executions>
            <execution>
              <id>redhat-enforce</id>
            </execution>
          </executions>
          <goals>
            <goal>enforce</goal>
          </goals>
        </plugin>
      </plugins>
    </profile>
</profiles>
于 2012-03-26T17:33:05.480 回答