1

We have a corporate parent POM that defines how projects are built. We have also bought a product (Visual Rules) that requires a totally separate build with totally separate plugins.

So, the natural solution is to use a Maven profile for that. However, the Visual Rules plugins don't check whether they're executed for a POM or for a module. This means that simply activating the profile (-Pvisual-rules in my case) will fail the build, since the plugins look for specific files, which don't exist in the parent project, only in the modules.

The profile in the corporate parent POM looks like this:

<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>

(If anyone has a better solution about how to skip the build only for the parent project, feel free to comment...)

So, activating on the command line doesn't work.

Next possibility: Activate by an existing file: The modules have the Visual Rules specific files in src/main/resources/ - and of course, the parent project doesn't have any Visual Rules files. This means I can activate the profile in the parent project using this:

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

Using mvn help:active-profiles clean package I now get the following output:

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!

But although the visual-rules profile is shown as active, the plugins within the profile are not started - why?

Just to be sure, I also started the build using mvn help:active-profiles clean package -Pvisual-rules, and here the plugins were started and caused the problem described above.

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

Perhaps I don't really understand Maven profile activation, but this seems pretty weird to me... Any help is really appreciated!

eerriicc
  • 1,124
  • 4
  • 17
  • 29
  • `mvn clean package -P visual-rules` you have a space missing. Try the one which added and see if that works – Clover Feb 28 '19 at 10:40
  • Thanks, but the result is the same. – eerriicc Feb 28 '19 at 12:01
  • _RuleModel Referenced element "general-rules-data" not found_ .Looks like maven is trying to find general-rules-data – Clover Feb 28 '19 at 12:16
  • Yes, that's Visual Rules doing its thing... However, the Visual Rules plugins should not execute for the parent project. – eerriicc Feb 28 '19 at 12:23
  • so basically you want to skip the modules with visual rules files in them(resource)? correct me if wrong. – Clover Feb 28 '19 at 12:54
  • No, I want to activate the profile `visual-rules` for the modules (which contain src/main/resources), but not for the parent project. – eerriicc Feb 28 '19 at 13:06
  • https://stackoverflow.com/questions/11620566/how-to-activate-a-maven-profile-for-a-specific-module-in-a-mutli-module-project check this – Clover Feb 28 '19 at 13:19
  • Do you see any of the Visual Rules plugins attempting to run if you use debug mode (`-X`)? Also, you show a "visual-rules" profile with an activation but no plugins, is that just for brevity of the question? – user944849 Feb 28 '19 at 14:03
  • @Clover: Activating the profile with `-DprofileIdEnabled=true` (as suggested in the anwer) gives me the same result as activating by file (my second solution): The profile is shown as active, but doesn't do anything. – eerriicc Mar 01 '19 at 08:44
  • @user944849: I changed the question to document the `visual-rules` profile in the corporate parent POM. The profile shown in the project is there to activate the profile in the corporate parent POM. Anyway, using `-X` doesn't show any Visual Rules plugin being active either. – eerriicc Mar 01 '19 at 08:56
  • Well, to me it looks like the profile in the module is not activating the profile in the corporate parent POM, but rather overwriting it. And since it's empty, it doesn't do anything. Is that the way Maven profiles work in this case? – eerriicc Mar 01 '19 at 09:47

1 Answers1

0

It looks like defining the profile with the same ID and the activation overrides the profile in the corporate parent POM. And since that profile in the module doesn't contain anything, the profile is shown as active but doesn't start any plugins.

So, in the end I did the following:

In the corporate parent POM, I changed the profile 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>

And thus every module which wants to activate this profile needs to have a dummy file build-visual-rule in its root directory (next to its POM file).

eerriicc
  • 1,124
  • 4
  • 17
  • 29