Skip to content

Update Groovy version to 5.0.x #5289

Closed
Closed

Description

@fmbenhassine

When updating Groovy version to the latest 5.0.4, the GroovyJobFunctionalTests fails with:

java.lang.IllegalStateException: Failed to load ApplicationContext for [MergedContextConfiguration@704d3b00 testClass = org.springframework.batch.samples.misc.groovy.GroovyJobFunctionalTests, locations = ["classpath:/org/springframework/batch/samples/misc/groovy/job/groovyJob.xml", "classpath:/simple-job-launcher-context.xml"], classes = [], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = [], contextCustomizers = [org.springframework.test.context.support.DynamicPropertiesContextCustomizer@0], contextLoader = org.springframework.test.context.support.DelegatingSmartContextLoader, parent = null]

	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.lambda$loadContext$0(DefaultCacheAwareContextLoaderDelegate.java:195)
	at org.springframework.test.context.cache.DefaultContextCache.put(DefaultContextCache.java:214)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:160)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:128)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:155)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:111)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
	at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:205)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1716)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:153)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:176)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:632)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'unzip-script': BeanPostProcessor before instantiation of bean failed
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:371)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:331)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1218)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1184)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1121)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:993)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:620)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:253)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:111)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:213)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:247)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.lambda$loadContext$0(DefaultCacheAwareContextLoaderDelegate.java:167)
	... 21 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'unzip-script': Could not determine scripted object type for GroovyScriptFactory: script source locator [inline:
			class UnzipTasklet {
			void execute() {
			def ant = new AntBuilder()
			ant.unzip(src:"src/main/resources/org/springframework/batch/samples/misc/groovy/data/files.zip",
			dest:"target/groovyJob/staging")
			}
			}
		]
	at org.springframework.scripting.support.ScriptFactoryPostProcessor.postProcessBeforeInstantiation(ScriptFactoryPostProcessor.java:327)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1157)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1133)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
	... 35 more
Caused by: org.springframework.scripting.ScriptCompilationException: Could not compile static script [scriptFactory.unzip-script]
	at org.springframework.scripting.groovy.GroovyScriptFactory.getScriptedObjectType(GroovyScriptFactory.java:288)
	at org.springframework.scripting.support.ScriptFactoryPostProcessor.postProcessBeforeInstantiation(ScriptFactoryPostProcessor.java:320)
	... 38 more
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
scriptFactory.unzip-script: 4: unable to resolve class AntBuilder
 @ line 4, column 14.
   			def ant = new AntBuilder()
                ^

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:292)
	at org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:894)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:668)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:642)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:399)
	at groovy.lang.GroovyClassLoader.lambda$parseClass$5(GroovyClassLoader.java:345)
	at org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:138)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:345)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:329)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:303)
	at org.springframework.scripting.groovy.GroovyScriptFactory.getScriptedObjectType(GroovyScriptFactory.java:269)
	... 39 more

Even if the class AntBuilder is present in groovy-ant-5.0.4 jar.


Patch to update groovy version:

Index: pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/pom.xml b/pom.xml
--- a/pom.xml	(revision 2e9755dca1e1eef9efd99cf6cb4e30727c46dbd6)
+++ b/pom.xml	(date 1770972869937)
@@ -129,7 +129,7 @@
 		<spring-rabbit.version>${spring-amqp.version}</spring-rabbit.version>
 		<quartz.version>2.5.1</quartz.version>
 		<prometheus-metrics-exporter-pushgateway>1.4.2</prometheus-metrics-exporter-pushgateway>
-		<groovy.version>3.0.25</groovy.version> <!-- change to org.apache.groovy:groovy + update to latest 5.0.2 -->
+		<groovy.version>5.0.4</groovy.version>
         <logback.version>1.5.21</logback.version>
 
 		<!-- documentation dependencies -->
Index: spring-batch-samples/pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml
--- a/spring-batch-samples/pom.xml	(revision 2e9755dca1e1eef9efd99cf6cb4e30727c46dbd6)
+++ b/spring-batch-samples/pom.xml	(date 1770973379145)
@@ -282,13 +282,13 @@
 			<version>${hsqldb.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>org.codehaus.groovy</groupId>
+			<groupId>org.apache.groovy</groupId>
 			<artifactId>groovy</artifactId>
 			<version>${groovy.version}</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
-			<groupId>org.codehaus.groovy</groupId>
+			<groupId>org.apache.groovy</groupId>
 			<artifactId>groovy-ant</artifactId>
 			<version>${groovy.version}</version>
 			<scope>test</scope>

Activity

  1. added a commit that references this issue on Mar 10, 2026
    97fc0c1
  2. KMGeon commented on Mar 10, 2026

    @KMGeon
    Contributor

    Hi @fmbenhassine,

    The root cause of this issue is that AntBuilder was moved from groovy.util to groovy.ant in Groovy 3.0 to resolve the JPMS split package problem.

    In Groovy 2.x, groovy.util.AntBuilder was part of the default auto-import, so it could be used without an explicit import. In Groovy 3.0, the class was copied to groovy.ant.AntBuilder and the old location was marked @Deprecated. Then in Groovy 4.0, the legacy groovy.util.AntBuilder was completely removed. Since groovy.ant.* is not an auto-import target, upgrading to Groovy 5.0.x causes new AntBuilder() to fail with "unable to resolve class AntBuilder".

    References:

    Fix: Add import groovy.ant.AntBuilder at the top of each <lang:inline-script> block in groovyJob.xml.

    <lang:inline-script>
        import groovy.ant.AntBuilder
        class UnzipTasklet {
            ...
        }
    </lang:inline-script>
  3. added a commit that references this issue on Sep 18, 2026
    264e102
  4. added a commit that references this issue on Sep 18, 2026
    a880092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions