Skip to content

Upgrade to Groovy 3.0.7 #24946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions spring-boot-project/spring-boot-cli/samples/http.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.test

@Grab("org.codehaus.groovy.modules.http-builder:http-builder:0.5.2") // This one just to test dependency resolution
import groovyx.net.http.*
import org.springframework.web.client.RestTemplate;

@Controller
class Example implements CommandLineRunner {
Expand All @@ -17,7 +16,7 @@ class Example implements CommandLineRunner {

void run(String... args) {
def port = context.webServer.port
def world = new RESTClient("http://localhost:" + port).get(path:"/").data.text
def world = new RestTemplate().getForObject("http://localhost:" + port + "/", String.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def world = new RestTemplate().getForObject("http://localhost:" + port + "/", String.class);
def world = new RestTemplate().getForObject("http://localhost:$port/", String.class);

It's more the Groovy way :).

Copy link
Contributor

@szpak szpak Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I would put here int and String instead of just def for clarity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look, @szpak. Those are good changes to make, but they're unrelated to an upgrade to Groovy 3.0 so let's keep them separate from this PR please.

print "Hello " + world
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -216,16 +217,16 @@ public Class<?>[] compile(String... sources) throws CompilationFailedException,

@SuppressWarnings("rawtypes")
private void addAstTransformations(CompilationUnit compilationUnit) {
LinkedList[] phaseOperations = getPhaseOperations(compilationUnit);
processConversionOperations(phaseOperations[Phases.CONVERSION]);
Deque[] phaseOperations = getPhaseOperations(compilationUnit);
processConversionOperations((LinkedList) phaseOperations[Phases.CONVERSION]);
}

@SuppressWarnings("rawtypes")
private LinkedList[] getPhaseOperations(CompilationUnit compilationUnit) {
private Deque[] getPhaseOperations(CompilationUnit compilationUnit) {
try {
Field field = CompilationUnit.class.getDeclaredField("phaseOperations");
field.setAccessible(true);
return (LinkedList[]) field.get(compilationUnit);
return (Deque[]) field.get(compilationUnit);
}
catch (Exception ex) {
throw new IllegalStateException("Phase operations not available from compilation unit");
Expand Down Expand Up @@ -270,11 +271,12 @@ public void call(SourceUnit source, GeneratorContext context, ClassNode classNod
throws CompilationFailedException {

ImportCustomizer importCustomizer = new SmartImportCustomizer(source);
ClassNode mainClassNode = MainClass.get(source.getAST().getClasses());
List<ClassNode> classNodes = source.getAST().getClasses();
ClassNode mainClassNode = MainClass.get(classNodes);

// Additional auto configuration
for (CompilerAutoConfiguration autoConfiguration : GroovyCompiler.this.compilerAutoConfigurations) {
if (autoConfiguration.matches(classNode)) {
if (classNodes.stream().anyMatch(autoConfiguration::matches)) {
if (GroovyCompiler.this.configuration.isGuessImports()) {
autoConfiguration.applyImports(importCustomizer);
importCustomizer.call(source, context, classNode);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -87,7 +87,8 @@ void setUpExpectations() {

@Test
void transformationOfAnnotationOnImport() {
this.moduleNode.addImport(null, null, Arrays.asList(this.grabAnnotation));
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing null throws an NPE these days.

this.moduleNode.addImport("alias", classNode, Arrays.asList(this.grabAnnotation));
assertGrabAnnotationHasBeenTransformed();
}

Expand All @@ -100,14 +101,16 @@ void transformationOfAnnotationOnStarImport() {

@Test
void transformationOfAnnotationOnStaticImport() {
this.moduleNode.addStaticImport(null, null, null, Arrays.asList(this.grabAnnotation));
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addStaticImport(classNode, "field", "alias", Arrays.asList(this.grabAnnotation));

assertGrabAnnotationHasBeenTransformed();
}

@Test
void transformationOfAnnotationOnStaticStarImport() {
this.moduleNode.addStaticStarImport(null, null, Arrays.asList(this.grabAnnotation));
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addStaticStarImport("test", classNode, Arrays.asList(this.grabAnnotation));

assertGrabAnnotationHasBeenTransformed();
}
Expand Down
5 changes: 1 addition & 4 deletions spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ bom {
]
}
}
library("Groovy", "2.5.14") {
library("Groovy", "3.0.7") {
group("org.codehaus.groovy") {
imports = [
"groovy-bom"
Expand Down Expand Up @@ -1322,9 +1322,6 @@ bom {
}
}
library("REST Assured", "4.2.1") {
prohibit("[4.3.0,)") {
because "it requires Groovy 3"
}
group("io.rest-assured") {
modules = [
"json-path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8044,8 +8044,10 @@ Alternatively, you can specify a source for your test, which disables the behavi
==== Using Spock to Test Spring Boot Applications
If you wish to use Spock to test a Spring Boot application, you should add a dependency on Spock's `spock-spring` module to your application's build.
`spock-spring` integrates Spring's test framework into Spock.
It is recommended that you use Spock 1.2 or later to benefit from a number of improvements to Spock's Spring Framework and Spring Boot integration.
See http://spockframework.org/spock/docs/1.2/modules.html#_spring_module[the documentation for Spock's Spring module] for further details.
See http://spockframework.org/spock/docs/2.0-M4/modules.html#_spring_module[the documentation for Spock's Spring module] for further details.

NOTE: As of Spring Boot 2.5.x and its support for Groovy 3.x you have two options to make use of Spock:
Either use the latest Spock 2.0 milestone or release that is compatible with Groovy 3.x or stick with Spock 1.3 and downgrade Spring Boot's Groovy version to 2.5.x.



Expand Down
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-parent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bom {
]
}
}
library("Spock Framework", "1.3-groovy-2.5") {
library("Spock Framework", "2.0-M4-groovy-3.0") {
group("org.spockframework") {
modules = [
"spock-core",
Expand Down