Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequirePropertyDiverges evaluates in own context #282

Closed
delanym opened this issue Feb 12, 2024 · 3 comments · Fixed by #295
Closed

RequirePropertyDiverges evaluates in own context #282

delanym opened this issue Feb 12, 2024 · 3 comments · Fixed by #295

Comments

@delanym
Copy link

delanym commented Feb 12, 2024

I have 2 projects, a "build configuration" project A, and a multi-module project B.
A includes maven-enforcer-plugin configuration with a rule

          <execution>
            <id>module</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <phase>validate</phase>
            <configuration>
              <fail>true</fail>
              <rules>
                <requirePropertyDiverges>
                  <property>project.description</property>
                </requirePropertyDiverges>
              </rules>
            </configuration>
          </execution>

B inherits from A, but they are completely separate projects. I always need to rebuild A before seeing the inherited effects in B.

I expect this rule to fail for any module in B without a description tag, or where the description is the same as the parent. I get no failures when I should (and logs show the rule fires for each module in B).

If I move the rule configuration from A to B I get failures.
I suspect the rule is not being "lazy" when it should. It seems to be evaluating in the context of the project it was built, and not the project it is run, if that makes sense.

If someone can confirm this hunch it might lead to a fix, but I don't have time to create a reproducer at this point.

@delanym
Copy link
Author

delanym commented Feb 12, 2024

Perhaps this should be another issue, but the rule ignores sub-modules that lack the property in question altogether. This is surely a bug. The rule should evaluate the project model, not the file.

@piercemar
Copy link
Contributor

Hello,
The "reference" value used for the requirePropertyDiverges rule, is the one computed for the project that defined the rule.

So your project B would fail only if the "main" pom has no description (the rule is skipped for the defining project), but not for child modules.
For my own purpose, I use a modified version of requirePropertyDiverges that accepts an additional "reference" parameter that can take 3 values : DEFINING, PARENT or BASE.

  • DEFINING being the current behaviour of using the project defining the rule as reference
  • PARENT being the direct parent project if it exists
  • BASE being the top-most local project of your multi-module reactor.

I'd happily contribute a PR if someone deems it a worthy addition.

@slawekjaranowski
Copy link
Member

I'd happily contribute a PR if someone deems it a worthy addition.

Please create a PR, you can mention me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants