diff --git a/build.gradle b/build.gradle index ae100cb697f..f5c5f4e4729 100644 --- a/build.gradle +++ b/build.gradle @@ -216,10 +216,13 @@ if (isReleaseVersion) { allprojects { // FORCE UPGRADE OF GROOVY IN DEPENDENCIES TO GROOVY 4 - configurations.configureEach { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != 'groovy-bom') { - details.useTarget(group: 'org.apache.groovy', name: details.requested.name, version: groovyVersion) + // except in projects that will be run by Gradle during the build + if (!compiledByGradleGroovyVersion(project)) { + configurations.configureEach { + resolutionStrategy.eachDependency { DependencyResolveDetails details -> + if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != 'groovy-bom') { + details.useTarget(group: 'org.apache.groovy', name: details.requested.name, version: groovyVersion) + } } } } @@ -435,9 +438,6 @@ subprojects { project -> if (project.name == 'grails-dependencies') return if (project.name == 'grails-bom') return - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - if (project.name =~ /^(grails-web|grails-plugin-|grails-test-suite|grails-test)/) { dependencies { api "jakarta.servlet:jakarta.servlet-api:$servletApiVersion" @@ -478,14 +478,17 @@ subprojects { project -> dependencies { documentation("org.fusesource.jansi:jansi:$jansiVersion") documentation("jline:jline:$jlineVersion") - documentation "org.apache.groovy:groovy-ant:$groovyVersion" - documentation "org.apache.groovy:groovy-cli-picocli:$groovyVersion" documentation ("com.github.javaparser:javaparser-core:$javaParserCoreVersion") - if (project.name =~ /^(grails-bootstrap)/ || project.name =~ /^(grails-gradle-model)/) { - compileOnly groovyDependency + if (compiledByGradleGroovyVersion(project)) { + documentation "org.codehaus.groovy:groovy:$GroovySystem.version" + documentation "org.codehaus.groovy:groovy-ant:$GroovySystem.version" + documentation "org.codehaus.groovy:groovy-cli-picocli:$GroovySystem.version" } else { api groovyDependency + documentation "org.apache.groovy:groovy:$groovyVersion" + documentation "org.apache.groovy:groovy-ant:$groovyVersion" + documentation "org.apache.groovy:groovy-cli-picocli:$groovyVersion" } testImplementation "org.apache.groovy:groovy-test-junit5:$groovyVersion" @@ -602,6 +605,12 @@ subprojects { project -> jvmArgs += debugArguments } } + + java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } + } } // From this point on we need the subprojects to be fully configured, so force their full evaluation @@ -643,3 +652,11 @@ project.afterEvaluate { } } } + +// compile with the Groovy version provided by Gradle +// to ensure build compatibility with Gradle, currently Groovy 3.0.x +// when used by grails-gradle-plugin +// see: https://docs.gradle.org/current/userguide/compatibility.html#groovy +boolean compiledByGradleGroovyVersion(Project currentProject) { + currentProject.name in ['grails-bootstrap', 'grails-gradle-model', 'grails-shell'] +} diff --git a/gradle.properties b/gradle.properties index 30ece0c0821..0d6bc54a3e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,7 +20,7 @@ gradleNexusPluginVersion=2.3.1 gradleNexusPublishPluginVersion=1.3.0 gradleExtraConfigurationsPluginVersion=10.0.1 gradleLicensePluginVersion=0.16.1 -groovyVersion=4.0.22 +groovyVersion=4.0.23 gspVersion=7.0.0-SNAPSHOT hamcrestVersion=3.0 h2Version=2.2.224 diff --git a/gradle/docs.gradle b/gradle/docs.gradle index dcafb4fe057..bb46aa2996d 100644 --- a/gradle/docs.gradle +++ b/gradle/docs.gradle @@ -17,7 +17,11 @@ configurations { } dependencies { - documentation "org.apache.groovy:groovy-groovydoc:$groovyVersion" + if (compiledByGradleGroovyVersion(project)) { + documentation "org.codehaus.groovy:groovy-groovydoc:$GroovySystem.version" + } else { + documentation "org.apache.groovy:groovy-groovydoc:$groovyVersion" + } } ext.grailsDocSrc = project.findProperty('grails-doc.home') ?: project.buildDir.absolutePath + "/checkout/grails-docs-src" @@ -89,7 +93,8 @@ task javadoc(type:Javadoc, group: 'documentation') { tasks.register('groovydoc', Groovydoc) { final Set subProjects = subprojects.findAll { - it.name != 'grails-dependencies' && it.name != 'grails-bom' && !it.name.startsWith("grails-test-suite") } + !(it.name in ['grails-dependencies', 'grails-bom', 'grails-bootstrap', 'grails-gradle-model', 'grails-shell']) + && !it.name.startsWith("grails-test-suite") } def groovydocClasspath = files(configurations.documentation + subProjects.configurations.compileClasspath) // exclude problematic jar file from javadoc classpath // http://www.adam-bien.com/roller/abien/entry/trouble_with_crippled_java_ee diff --git a/grails-bootstrap/build.gradle b/grails-bootstrap/build.gradle index e5c2fda8747..1c7e5e570f4 100644 --- a/grails-bootstrap/build.gradle +++ b/grails-bootstrap/build.gradle @@ -1,23 +1,29 @@ import org.apache.tools.ant.filters.ReplaceTokens dependencies { - compileOnly ( "org.apache.groovy:groovy-xml:$groovyVersion" ) - compileOnly ( "org.apache.groovy:groovy-templates:$groovyVersion" ) - api "org.yaml:snakeyaml:$snakeyamlVersion" - api "io.micronaut:micronaut-inject:$micronautVersion" - - compileOnly("io.methvin:directory-watcher:$directoryWatcherVersion") - compileOnly("org.fusesource.jansi:jansi:$jansiVersion") - compileOnly("jline:jline:$jlineVersion") - compileOnly("net.java.dev.jna:jna:$jnaVersion") + // compile grails-bootstap with the Groovy version provided by Gradle + // to ensure build compatibility with Gradle, currently Groovy 3.0.x + // when used by grails-gradle-plugin + // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy + compileOnly "org.codehaus.groovy:groovy:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-templates:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-xml:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-ant:$GroovySystem.version" + + compileOnly "io.methvin:directory-watcher:$directoryWatcherVersion" + compileOnly "org.fusesource.jansi:jansi:$jansiVersion" + compileOnly "jline:jline:$jlineVersion" + compileOnly "net.java.dev.jna:jna:$jnaVersion" - // Ant - compileOnly "org.apache.groovy:groovy-ant:$groovyVersion" - testImplementation ( "org.apache.groovy:groovy-xml:$groovyVersion" ) - testImplementation ( "org.apache.groovy:groovy-templates:$groovyVersion" ) - testImplementation("org.fusesource.jansi:jansi:$jansiVersion") - testImplementation("jline:jline:$jlineVersion") + api "org.yaml:snakeyaml:$snakeyamlVersion" + api "io.micronaut:micronaut-inject:$micronautVersion", { + exclude group: 'org.apache.groovy' + } + testImplementation "org.apache.groovy:groovy-xml:$groovyVersion" + testImplementation "org.apache.groovy:groovy-templates:$groovyVersion" + testImplementation "org.fusesource.jansi:jansi:$jansiVersion" + testImplementation "jline:jline:$jlineVersion" } processResources { diff --git a/grails-core/src/main/groovy/org/grails/compiler/injection/EntityASTTransformation.java b/grails-core/src/main/groovy/org/grails/compiler/injection/EntityASTTransformation.java index 6aec5952d0f..680a54ccffa 100644 --- a/grails-core/src/main/groovy/org/grails/compiler/injection/EntityASTTransformation.java +++ b/grails-core/src/main/groovy/org/grails/compiler/injection/EntityASTTransformation.java @@ -43,14 +43,17 @@ public class EntityASTTransformation implements ASTTransformation, CompilationUn public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { - if (!(astNodes[0] instanceof AnnotationNode node) || !(astNodes[1] instanceof AnnotatedNode parent)) { + if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class"); } - if (!MY_TYPE.equals(node.getClassNode()) || !(parent instanceof ClassNode cNode)) { + AnnotatedNode parent = (AnnotatedNode) astNodes[1]; + AnnotationNode node = (AnnotationNode) astNodes[0]; + if (!MY_TYPE.equals(node.getClassNode()) || !(parent instanceof ClassNode)) { return; } + ClassNode cNode = (ClassNode) parent; String cName = cNode.getName(); if (cNode.isInterface()) { throw new RuntimeException("Error processing interface '" + cName + "'. " + diff --git a/grails-gradle-model/build.gradle b/grails-gradle-model/build.gradle new file mode 100644 index 00000000000..85a462da444 --- /dev/null +++ b/grails-gradle-model/build.gradle @@ -0,0 +1,7 @@ +dependencies { + // compile grails-gradle-model with the Groovy version provided by Gradle + // to ensure build compatibility with Gradle, currently Groovy 3.0.x + // when used by grails-gradle-plugin + // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy + compileOnly "org.codehaus.groovy:groovy:$GroovySystem.version" +} diff --git a/grails-shell/build.gradle b/grails-shell/build.gradle index b99907027f9..5128fb0b7bf 100644 --- a/grails-shell/build.gradle +++ b/grails-shell/build.gradle @@ -11,17 +11,27 @@ ext { } dependencies { + // compile grails-shell with the Groovy version provided by Gradle + // to ensure build compatibility with Gradle, currently Groovy 3.0.x + // when used by grails-gradle-plugin + // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy + compileOnly "org.codehaus.groovy:groovy:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-templates:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-xml:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-ant:$GroovySystem.version" + compileOnly "org.codehaus.groovy:groovy-json:$GroovySystem.version" + + runtimeOnly "org.apache.groovy:groovy-ant:$groovyVersion" + runtimeOnly "org.apache.groovy:groovy-json:$groovyVersion" + runtimeOnly "org.apache.groovy:groovy-jmx:$groovyVersion" + runtimeOnly "org.apache.groovy:groovy-xml:$groovyVersion" + api project(":grails-bootstrap") api project(":grails-gradle-model") api "org.apache.ant:ant:$antVersion" - api "org.apache.groovy:groovy-ant:$groovyVersion" - api "org.apache.groovy:groovy-json:$groovyVersion" - api "org.apache.groovy:groovy-jmx:$groovyVersion" api "org.fusesource.jansi:jansi:$jansiVersion" api "jline:jline:$jlineVersion" api "org.gradle:gradle-tooling-api:$gradleToolingApiVersion" - compileOnly "org.apache.groovy:groovy-templates:$groovyVersion" - api "org.apache.groovy:groovy-xml:$groovyVersion" compileOnly "org.springframework.boot:spring-boot:$springBootVersion" compileOnly "org.springframework.boot:spring-boot-loader-tools:$springBootVersion" @@ -56,6 +66,10 @@ dependencies { testImplementation "net.sf.expectit:expectit-core:$expectitCoreVersion" testImplementation "com.github.jnr:jnr-posix:$jnrPosixVersion" + testImplementation "org.apache.groovy:groovy-xml:$groovyVersion" + testImplementation "org.apache.groovy:groovy-json:$groovyVersion" + testImplementation "org.apache.groovy:groovy-templates:$groovyVersion" + testImplementation "org.apache.groovy:groovy-ant:$groovyVersion" runtimeOnly "org.slf4j:slf4j-simple:$slf4jVersion" runtimeOnly "org.codehaus.plexus:plexus-component-api:$plexusComponentApiVersion" diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingEvaluator.java b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingEvaluator.java index 16a614c3e0c..2cdc4e25b5a 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingEvaluator.java +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingEvaluator.java @@ -147,10 +147,11 @@ public List evaluateMappings(Resource resource) { @Override public List evaluateMappings(Class mappingsClass) { - var obj = (GroovyObject) BeanUtils.instantiateClass(mappingsClass); - if (obj instanceof Script script) { - var binding = new Binding(); - var closure = new MappingCapturingClosure(script); + GroovyObject obj = (GroovyObject) BeanUtils.instantiateClass(mappingsClass); + if (obj instanceof Script) { + Script script = (Script) obj; + Binding binding = new Binding(); + MappingCapturingClosure closure = new MappingCapturingClosure(script); binding.setVariable("mappings", closure); script.setBinding(binding); script.run(); @@ -596,8 +597,10 @@ private Object _invoke(String methodName, Object arg, Object delegate) { urlDefiningMode = false; } args = args != null && args.length > 0 ? args : new Object[] {Collections.emptyMap()}; - if (args[0] instanceof Closure callable) { - var urlData = createUrlMappingData(mappedURI, isResponseCode); + if (args[0] instanceof Closure) { + UrlMappingData urlData = createUrlMappingData(mappedURI, isResponseCode); + + Closure callable = (Closure) args[0]; if (delegate != null) { callable.setDelegate(delegate); @@ -638,7 +641,8 @@ private Object _invoke(String methodName, Object arg, Object delegate) { return urlMapping; } - if (args[0] instanceof Map namedArguments) { + if (args[0] instanceof Map) { + Map namedArguments = (Map) args[0]; String version = null; if (namedArguments.containsKey(UrlMapping.VERSION)) { @@ -704,7 +708,8 @@ private Object _invoke(String methodName, Object arg, Object delegate) { } } } else if ((!urlDefiningMode || (!parentResources.isEmpty() && parentResources.peek().isGroup)) && CONSTRAINTS.equals(mappedURI)) { - if (args.length > 0 && (args[0] instanceof Closure callable)) { + if (args.length > 0 && (args[0] instanceof Closure)) { + Closure callable = (Closure) args[0]; var builder = constraintsEvaluator.newConstrainedPropertyBuilder(UrlMapping.class); for (var constrainedProperty : currentConstraints) { builder.getConstrainedProperties().put(constrainedProperty.getPropertyName(), constrainedProperty); @@ -729,7 +734,8 @@ private List calculateIncludes(Map namedArguments, List def Object excludesObject = namedArguments.get("excludes"); if (excludesObject != null) { - if (excludesObject instanceof List excludeList) { + if (excludesObject instanceof List) { + List excludeList = (List) excludesObject; for (Object exc : excludeList) { if (exc != null) { includes.remove(exc.toString().toLowerCase()); @@ -741,7 +747,8 @@ private List calculateIncludes(Map namedArguments, List def } Object includesObject = namedArguments.get("includes"); if (includesObject != null) { - if (includesObject instanceof List includeList) { + if (includesObject instanceof List) { + List includeList = (List) includesObject; includes.clear(); for (Object inc : includeList) { if (inc != null) { @@ -1079,7 +1086,8 @@ private UrlMapping getURLMappingForNamedArgs(Map namedArguments, UrlMapping var exceptionArg = getException(namedArguments, bindingVariables); if (isResponseCode && exceptionArg != null) { - if (exceptionArg instanceof Class exClass) { + if (exceptionArg instanceof Class) { + Class exClass = (Class) exceptionArg; if (Throwable.class.isAssignableFrom(exClass)) { ((ResponseCodeUrlMapping) urlMapping).setExceptionType(exClass); } else {