grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Simplify Dependency Resolution

Open codeconsole opened this issue 1 year ago • 1 comments
trafficstars

Cleanup in dependency resolution.

We are using excludes in too many locations. excludes, with a few exceptions, should not be necessary. If it is ever used, they should be very specific. For instance, if there is just 2 modules that have a specific dependency that needs to be excluded, the exclusion should only apply to those 2 modules.

Dependencies should not be transitive unless they are needed 100% of the time by the final application. For instance, if a project uses ehcache, but it is optional and only turned on/off via a configuration option, it should not be transitive.

  1. identify plugins that use @AstTransformer and determine what imports are required for successful compilation.
  2. Use compileOnlyAPI, but only if that dependency is not already transitively resolved compileOnlyAPI by a dependency on an another plugin that it depends on.
  3. Identify all exclusions across the code base and determine why they are needed and what is necessary for their removal.
  4. Use the grails bom when able. Do not specify dependency versions in a plugin unless they are specific to that plugin.

https://docs.gradle.org/current/userguide/java_library_plugin.html

codeconsole avatar Oct 16 '24 16:10 codeconsole

compileOnlyAPI is still not an ideal solution and should be avoided at all costs. The reason for needing the dependency should be addressed first.

For instance, servlet api references should not be compiled into every controller class

https://github.com/grails/grails-core/blob/621e90508fa58535dcf3ad0f226a4dba92125f5e/grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java#L88

just to reference a constant.

https://github.com/grails/grails-core/blob/621e90508fa58535dcf3ad0f226a4dba92125f5e/grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java#L546

Instead, the constant should be added to a separate class and referenced instead.

codeconsole avatar Oct 16 '24 20:10 codeconsole