Skip to content

Conversation

@matrei
Copy link
Contributor

@matrei matrei commented Oct 29, 2025

Supersedes #14737

@matrei matrei mentioned this pull request Oct 29, 2025
# Conflicts:
#	buildSrc/build.gradle
#	dependencies.gradle
#	grails-bootstrap/src/main/groovy/org/grails/config/NavigableMap.groovy
#	grails-gradle/buildSrc/build.gradle
@jamesfredley jamesfredley added the relates-to:v8 Grails 8 label Feb 3, 2026
@jamesfredley jamesfredley changed the base branch from 7.0.x to 8.0.x February 4, 2026 16:24
# Conflicts:
#	dependencies.gradle
#	gradle/test-config.gradle
#	grails-forge/settings.gradle
#	settings.gradle
@jamesfredley
Copy link
Contributor

9574fe8 - should be a comprehensive list of the remaining Groovy 5 issues which need to be addressed, not necessary the solutions.

@jdaugherty
Copy link
Contributor

9574fe8 - should be a comprehensive list of the remaining Groovy 5 issues which need to be addressed, not necessary the solutions.

It seems the way we solved this was making it dynamically resolve, while before it was compilestatic. These don't seem like real solutions - the developer impact of method resolution is going to be very painful.

@jdaugherty
Copy link
Contributor

@jamesfredley we should recreate this PR so your change shows correctly in the diff history.

@jamesfredley
Copy link
Contributor

jamesfredley commented Feb 5, 2026

Why GormEntity Works but HibernateEntity Didn't

The issue is NOT that Groovy 5 prohibits static methods in traits. GormEntity has 87+ static methods and works fine.
The issue is joint compilation with Java files that directly import the trait.

Trait Module Static Methods Java Files Import It? Result
GormEntity grails-datamapping-core 87 No Works
HibernateEntity grails-data-hibernate5-core 5 Yes (HibernateMappingContext.java) Fails
MongoEntity grails-data-mongodb 18 No Works
Neo4jEntity grails-data-neo4j 10 No Works

The Technical Problem

When a Java file in the same module imports a Groovy trait with static methods that return generic type parameters (D), the Groovy stub generator creates invalid Java code:

// Generated stub (INVALID Java)
@groovy.transform.Generated() static java.util.List<D> findAllWithSql(java.lang.CharSequence sql);
//                                                   ^ ERROR: non-static type variable D 
//                                                            cannot be referenced from static context

In Java, you cannot use a class-level type parameter (D) in a static method signature. The Groovy trait works because Groovy handles this differently at runtime, but the Java stub generator doesn't account for this.


Protential Solution

Approach: Remove Java Import via Reflection

Instead of removing the static methods from the trait, we modified HibernateMappingContext.java to load HibernateEntity via reflection, avoiding the need for Java stubs:

Updated commit with this change: 425d2da

Approach: move class locations to other modules or change Java Class to Groovy Class

@jdaugherty these commits are not indented to be part of the real PR they are just a map for the real commit, it identifies everything that breaks trying to build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants