0

在 pom 中,我有一个工件 id 的参数:

    <dependency>
      <groupId>com.abc.automation</groupId>
      <artifactId>${app}-xyz-extension</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <type>test-jar</type>
    </dependency>

我打算强制任何人使用这个 pom 来传递参数 -Dapp ;为此,我正在使用强制插件:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>3.0.0-M3</version>
          <executions>
            <execution>
              <id>enforce-property</id>
              <phase>validate</phase>
              <goals>
                <goal>enforce</goal>
              </goals>
              <configuration>
                <rules>
                  <requireProperty>
                    <property>app</property>
                    <message>
                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                      You must set the app property!
                      This is used to determine which app is being tested and load the
                      corresponding extension.
                      Example: -Dapp=sampeapp
                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    </message>
                    <!--<regex>.*\d.*</regex>-->
                  </requireProperty>
                </rules>
                <fail>true</fail>
              </configuration>
            </execution>
          </executions>
        </plugin>

然而,这并不强制要求 -Dapp 必须是基础,而是我得到的是来自 pom 的错误

[错误] 构建无法读取 1 个项目-> [帮助 1] org.apache.maven.project.ProjectBuildingException:处理 POM 时遇到一些问题:[错误] com.abc 的“dependencies.dependency.artifactId”。自动化:${app}-xyz-extension:test-jar 的值为 '${app}-taas-extension' 与有效的 id 模式不匹配。@ 第 18 行,第 19 列

Plugins 元素放置在 build 中,如下所示:

<build>
<pluginManagement>
  <plugins>
    <plugin>
         ....
    </plugin>
  </plugins>
</pluginManagement>
</build>

我错过了强制插件的基础知识吗?

4

2 回答 2

1

Deepak,这可能是因为在执行插件之前写了占位符 ${app} 的其他插件/依赖项。

于 2020-09-15T07:02:56.267 回答
0

我猜你的插件定义在里面<pluginManagement>。将其移至<plugins>POM 的部分。

于 2020-09-03T06:38:08.733 回答