@@ -239,18 +239,12 @@ class GrailsGradlePlugin extends GroovyPlugin {
239239 starImports. add(' jakarta.validation.constraints' )
240240
241241 // Check for grails-datamapping-core (grails.gorm.annotation.*)
242- def datamappingCoreDep = project. configurations. getByName(' compileClasspath' ). dependencies. find { Dependency d ->
243- d. group == ' org.apache.grails.data' && d. name == ' grails-datamapping-core'
244- }
245- if (datamappingCoreDep) {
242+ if (hasDependency(project, ' compileClasspath' , ' org.apache.grails.data' , ' grails-datamapping-core' )) {
246243 starImports. add(' grails.gorm.annotation' )
247244 }
248245
249246 // Check for grails-scaffolding (grails.plugin.scaffolding.annotation.*)
250- def scaffoldingDep = project. configurations. getByName(' compileClasspath' ). dependencies. find { Dependency d ->
251- d. group == ' org.apache.grails' && d. name == ' grails-scaffolding'
252- }
253- if (scaffoldingDep) {
247+ if (hasDependency(project, ' compileClasspath' , ' org.apache.grails' , ' grails-scaffolding' )) {
254248 starImports. add(' grails.plugin.scaffolding.annotation' )
255249 }
256250 }
@@ -272,6 +266,32 @@ ${importStatements}
272266 }
273267 }
274268
269+ /**
270+ * Check if a dependency is present in the configuration hierarchy.
271+ * This checks all dependencies including those from parent configurations via extendsFrom.
272+ *
273+ * @param project The Gradle project
274+ * @param configurationName The configuration to check (e.g., 'compileClasspath')
275+ * @param group The dependency group (e.g., 'org.apache.grails.data')
276+ * @param name The dependency name (e.g., 'grails-datamapping-core')
277+ * @return true if the dependency is present in the configuration hierarchy
278+ */
279+ protected boolean hasDependency (Project project , String configurationName , String group , String name ) {
280+ try {
281+ def configuration = project. configurations. findByName(configurationName)
282+ if (configuration == null ) {
283+ return false
284+ }
285+
286+ return configuration. allDependencies. any { d ->
287+ d. group == group && d. name == name
288+ }
289+ } catch (Exception e) {
290+ project. logger. debug(" Failed to check for dependency ${ group} :${ name} in ${ configurationName} : ${ e.message} " )
291+ return false
292+ }
293+ }
294+
275295 protected void excludeDependencies (Project project ) {
276296 // Perhaps change to check that if this is a Grails plugin, don't exclude?
277297 // Adding an exclusion to every dependency in a pom is very verbose and
0 commit comments