kordamp / kordamp-gradle-plugins

A collection of Gradle plugins
https://kordamp.org/kordamp-gradle-plugins/
Apache License 2.0
138 stars 25 forks source link

Enforcer plugin: "Cannot notify listeners of type ProjectEvaluationListener..." messages #499

Closed ejbartelds closed 2 years ago

ejbartelds commented 2 years ago

I am following the docs (http://kordamp.org/enforcer-gradle-plugin/), trying to introduce the enforcer plugin to a multi-module project (Gradle 7.3.3, JDK 1.8, Kotlin DSL), but am encountering problems which I'll describe below.

I am aware this may be a case of RTFM and not an actual bug with the enforcer plugin. If that's the case, my apologies.

My project consists of several modules, each producing a jar artifact. There's one "main" project tying it all together (by depending on these other modules) and producing a Spring Boot executable jar.

I have a convention plugin which is used by all modules; I added the enforcer plugin to this convention plugin (without any rules configuration) thereby making the enforcer available to all modules.

Now I can add enforce { ... } blocks to all modules' build files.

If I add a BannedDependencies rule to my "main" module, I get an error:

> Could not resolve all dependencies for configuration ':app:ech-app:detachedConfiguration68'.
   > A problem occurred configuring project ':app:ech-ws'.
      > Cannot notify listeners of type ProjectEvaluationListener as these listeners are already being notified.

This behaviour is the same with or without exclude's present in the rule.

Now if instead I add a BannedDependencies rule to my other modules, some fail with the same error message, and some do not give any error at all but just correctly catch any configured banned dependencies.

Same occurs with the DependencyConvergence rule, but with a twist. If in fact in a given module identical dependencies with different versions are found, the enforcer reports:

> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':app:ech-ws:defaultCopy'.
      > Conflict(s) found for the following module(s):
          - commons-logging:commons-logging between versions 1.2 and 1.0.4

The list of reported conflicts is correct, but the "failed to notify..." message feels like there's something wrong somehow.

Clearly, I am doing something wrong :-( Please advise.

Thanks in advance

aalmiray commented 2 years ago

The enforcer plugin is hosted at https://github.com/kordamp/enforcer-gradle-plugin

You're likely experiencing the same problem as https://github.com/kordamp/enforcer-gradle-plugin/issues/22

One possible way to fix this is to use the project enforcer (configured at a project build file) instead of the build enforcer (configured at the settings file) for all rules that affect configurations (such as dependency convergence, exclusions, banned dependencies, etc).

ejbartelds commented 2 years ago

Thank you for your comment. The issue indeed appears the same or similar to problem #22. Thank you for your suggestions for a fix, but, try as I might, i haven't been able to solve the problem. Decision for now is, sadly, to not use the enforcer in our project(s).