Maven配置文件活跃,但不做任何事情 - 为什么



我们有一个公司父母POM来定义项目的构建方式。我们还购买了一个产品(视觉规则),该产品需要一个完全独立的插件。

因此,自然解决方案是为此使用Maven曲线。但是,视觉规则插件不会检查它们是为POM执行还是用于模块。这意味着简单地激活配置文件(在我的情况下为-Pvisual-rules)将使构建失败,因为插件会寻找特定的文件,而这些文件仅存在于父项目中,仅在模块中。

公司父母POM中的个人资料看起来像这样:

<profile>
  <id>visual-rules</id>
  <build>
    <plugins>
      <plugin>
        <groupId>de.visualrules.builder</groupId>
        <artifactId>visualrules-validation-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>validate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...and other Visual Rules plugins
    </plugins>
  </build>
</profile>

(如果有人对如何仅针对父项目跳过构建有更好的解决方案,请随时发表评论...

因此,在命令行上激活不起作用。

下一个可能性:通过现有文件激活:模块具有src/main/resources/中的视觉规则特定文件 - 当然,父级项目没有任何视觉规则文件。这意味着我可以使用以下方式激活父项目中的配置文件:

<profiles>
  <profile>
    <id>visual-rules</id>
    <activation>
      <file>
        <exists>src/main/resources</exists>
      </file>
    </activation>
  </profile>
</profiles>

使用mvn help:active-profiles clean package我现在获取以下输出:

10:10:31.788 [INFO] --- maven-help-plugin:3.1.0:active-profiles (default-cli) @ global-regeln ---
10:10:32.080 [INFO]
Active Profiles for Project 'foobar:global-regeln:pom:1.21.0-SNAPSHOT':
The following profiles are active:
 - default (source: external)
 - local (source: foobar:corporate-parent:1.52.0-SNAPSHOT)

Active Profiles for Project 'foobar:global-regeln-edossier-schlagwort-zu-doktyp:jar:1.21.0-SNAPSHOT':
The following profiles are active:
 - default (source: external)
 - visual-rules (source: foobar:global-regeln:1.21.0-SNAPSHOT)
 - local (source: foobar:corporate-parent:1.52.0-SNAPSHOT)

Active Profiles for Project 'foobar:global-regeln-zahlungspflichtdatum-fuer-gebuehrtyp:jar:1.21.0-SNAPSHOT':
The following profiles are active:
 - default (source: external)
 - visual-rules (source: foobar:global-regeln:1.21.0-SNAPSHOT)
 - local (source: foobar:corporate-parent:1.52.0-SNAPSHOT)

Active Profiles for Project 'foobar:global-regeln-fristberechnung:jar:1.21.0-SNAPSHOT':
The following profiles are active:
 - default (source: external)
 - visual-rules (source: foobar:global-regeln:1.21.0-SNAPSHOT)
 - local (source: foobar:corporate-parent:1.52.0-SNAPSHOT)

Active Profiles for Project 'foobar:global-regeln-terminberechnung:jar:1.21.0-SNAPSHOT':
The following profiles are active:
 - default (source: external)
 - visual-rules (source: foobar:global-regeln:1.21.0-SNAPSHOT)
 - local (source: foobar:corporate-parent:1.52.0-SNAPSHOT)
 ... Rest of the build, no Visual Rules plugin output!

但是,尽管visual-rules配置文件显示为活动,但未启动配置文件中的插件 - 为什么?

可以肯定的是,我还使用mvn help:active-profiles clean package -Pvisual-rules启动了构建,此处启动了插件并引起了上述问题。

10:18:50.608 [INFO] ------------------------------------------------------------------------
10:18:50.608 [INFO] Reactor Summary:
10:18:50.608 [INFO]
10:18:50.608 [INFO] Globale Regeln ..................................... FAILURE [  3.414 s]
10:18:50.608 [INFO] eDossierregeln-Schlagworte zu Dokumententypen ...... SKIPPED
10:18:50.608 [INFO] Globale Zahlungspflichtdatumberechnung-Regel ....... SKIPPED
10:18:50.608 [INFO] Globale Fristberechnung ............................ SKIPPED
10:18:50.608 [INFO] Globale Terminberechnung ........................... SKIPPED
10:18:50.608 [INFO] ------------------------------------------------------------------------
10:18:50.608 [INFO] BUILD FAILURE
10:18:50.608 [INFO] ------------------------------------------------------------------------
10:18:50.608 [INFO] Total time: 5.515 s
10:18:50.608 [INFO] Finished at: 2019-02-28T10:18:50+01:00
10:18:50.801 [INFO] Final Memory: 72M/793M
10:18:50.801 [INFO] ------------------------------------------------------------------------
10:18:50.803 [ERROR] Failed to execute goal de.visualrules.builder:visualrules-validation-maven-plugin:6.4.10:validate (default) on project global-regeln: RuleModel 'global-regeln-edossier-schlagwort-zu-doktyp' is not valid: Referenziertes Element "allgemein-regeln-fachdaten" nicht gefunden

也许我真的不理解Maven概况激活,但这对我来说似乎很奇怪...任何帮助都非常感谢!

它看起来像是使用相同的ID定义配置文件,并且激活覆盖公司父母POM中的配置文件。而且,由于模块中的该配置文件不包含任何内容,因此该配置文件显示为活动性,但没有启动任何插件。

所以,最后我做了以下操作:

在公司父母pom中,我更改了配置文件 visual-rules

<profile>
  <id>visual-rules</id>
  <activation>
    <file>
      <!-- Every Visual Rules module must have this dummy file in the root directory. -->
      <exists>build-visual-rules</exists>
    </file>
  </activation>
  <build>
    ... Plugins etc.
  </build>
</profile>

,因此每个想要激活此配置文件的模块都需要在其root Directory中具有一个虚拟文件build-visual-rule(旁边是POM文件旁边)。

最新更新