Skip to content
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

Spring boot plugin issue using gradle cache #39635

Closed
alexisgayte opened this issue Feb 20, 2024 · 17 comments
Closed

Spring boot plugin issue using gradle cache #39635

alexisgayte opened this issue Feb 20, 2024 · 17 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@alexisgayte
Copy link

alexisgayte commented Feb 20, 2024

#39326
Running Spring boot plugin with gradle 8.5 generate :

Configuration cache problems found in this build.
2 problems were found storing the configuration cache, 1 of which seems unique.

Task :bootJar of type org.springframework.boot.gradle.tasks.bundling.BootJar: execution of task ':bootJar' caused invocation of 'Task.project' in other task at execution time which is unsupported.
See https://docs.gradle.org/8.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
Execution of task ':bootJar' caused invocation of 'Task.project' by task ':resolveMainClassName' at execution time which is unsupported.
org.gradle.api.InvalidUserCodeException: Execution of task ':bootJar' caused invocation of 'Task.project' by task ':resolveMainClassName' at execution time which is unsupported.
	at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1.exception(DefaultProblemFactory.kt:52)
	at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onTaskExecutionAccessProblem(ConfigurationCacheProblemsListener.kt:116)
	at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onProjectAccess(ConfigurationCacheProblemsListener.kt:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:472)
	at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:454)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:83)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:69)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:443)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:431)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:43)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:66)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:443)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:232)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:203)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy80.onProjectAccess(Unknown Source)
	at org.gradle.configurationcache.AbstractTaskProjectAccessChecker.notifyProjectAccess(TaskExecutionAccessCheckers.kt:33)
	at org.gradle.api.internal.AbstractTask.getProject(AbstractTask.java:238)
	at org.gradle.api.DefaultTask.getProject(DefaultTask.java:59)
	at org.springframework.boot.gradle.plugin.ResolveMainClassName.lambda$readMainClassName$0(ResolveMainClassName.java:156)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.springframework.boot.gradle.plugin.ResolveMainClassName.readMainClassName(ResolveMainClassName.java:158)
	at org.springframework.boot.gradle.plugin.JavaPluginAction.lambda$configureBootJarTask$9(JavaPluginAction.java:182)
	at org.gradle.api.internal.provider.FlatMapProvider.doMapValue(FlatMapProvider.java:55)
	at org.gradle.api.internal.provider.FlatMapProvider.calculateOwnValue(FlatMapProvider.java:50)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateValue(AbstractMinimalProvider.java:108)
	at org.gradle.api.internal.provider.TransformBackedProvider.calculateOwnValue(TransformBackedProvider.java:82)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateValue(AbstractMinimalProvider.java:108)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.withFinalValue(AbstractMinimalProvider.java:164)
	at org.gradle.api.internal.provider.DefaultProperty.finalValue(DefaultProperty.java:133)
	at org.gradle.api.internal.provider.DefaultProperty.finalValue(DefaultProperty.java:26)
	at org.gradle.api.internal.provider.AbstractProperty.finalizeNow(AbstractProperty.java:245)
	at org.gradle.api.internal.provider.AbstractProperty.beforeRead(AbstractProperty.java:239)
	at org.gradle.api.internal.provider.AbstractProperty.calculateOwnValue(AbstractProperty.java:135)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.getOrNull(AbstractMinimalProvider.java:98)
	at org.gradle.api.internal.provider.ProviderResolutionStrategy$1.resolve(ProviderResolutionStrategy.java:27)
	at org.gradle.util.internal.DeferredUtil.unpack(DeferredUtil.java:59)
	at org.gradle.util.internal.DeferredUtil.unpackOrNull(DeferredUtil.java:49)

The issue is here :

https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java#L152-L161

We cannot call getProject().getProjectDir().toPath() at execution time

My understanding is that needs to be moved at the constructor level, here :
https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ResolveMainClassName.java#L67

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 20, 2024
@scottfrederick
Copy link
Contributor

@alexisgayte As was requested previously, please provide us with a complete minimal sample project that demonstrates the problem so we can run it ourselves.

@scottfrederick scottfrederick added the status: waiting-for-feedback We need additional information before we can continue label Feb 20, 2024
@alexisgayte
Copy link
Author

alexisgayte commented Feb 20, 2024

I have given the steps to reproduce it, doesn't seem to be consistent thought.
I closed the previous issue as I thought the issue was linked to another plugin as suggested.
However, it appears that the issue is with in the spring boot plugin.
The stack trace point to the failing point, which is clear. As the document said we cannot call "project" at execution time which is unsupported, altho the plugin is doing it.

but to be clear I have no idea how the plugin ended up calling : org.springframework.boot.gradle.plugin.JavaPluginAction.lambda$configureBootJarTask$9(JavaPluginAction.java:182)
then
org.springframework.boot.gradle.plugin.ResolveMainClassName.readMainClassName(ResolveMainClassName.java:158

But the fact that the plugin uses a nonauthrized method during the execution time is de facto an issue and the issue.

the issue seems to be linked to some tasks already cached thought.

EDIT : from the plugin code

	Provider<String> manifestStartClass = project
		.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
	bootJar.getMainClass()
		.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
				? manifestStartClass : resolveMainClassName.get().readMainClassName()));

manifestStartClass should be absent.
"Start-Class" should not be part of the manifest attributes.

here is the full stack trace if that can help:

org.gradle.api.InvalidUserCodeException: Execution of task ':bootJar' caused invocation of 'Task.project' by task ':resolveMainClassName' at execution time which is unsupported.
	at org.gradle.configurationcache.problems.DefaultProblemFactory$problem$1.exception(DefaultProblemFactory.kt:52)
	at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onTaskExecutionAccessProblem(ConfigurationCacheProblemsListener.kt:116)
	at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onProjectAccess(ConfigurationCacheProblemsListener.kt:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:472)
	at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:454)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:83)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:69)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:443)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:431)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:43)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:66)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:443)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:232)
	at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:203)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy80.onProjectAccess(Unknown Source)
	at org.gradle.configurationcache.AbstractTaskProjectAccessChecker.notifyProjectAccess(TaskExecutionAccessCheckers.kt:33)
	at org.gradle.api.internal.AbstractTask.getProject(AbstractTask.java:238)
	at org.gradle.api.DefaultTask.getProject(DefaultTask.java:59)
	at org.springframework.boot.gradle.plugin.ResolveMainClassName.lambda$readMainClassName$0(ResolveMainClassName.java:156)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.springframework.boot.gradle.plugin.ResolveMainClassName.readMainClassName(ResolveMainClassName.java:158)
	at org.springframework.boot.gradle.plugin.JavaPluginAction.lambda$configureBootJarTask$9(JavaPluginAction.java:182)
	at org.gradle.api.internal.provider.FlatMapProvider.doMapValue(FlatMapProvider.java:55)
	at org.gradle.api.internal.provider.FlatMapProvider.calculateOwnValue(FlatMapProvider.java:50)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateValue(AbstractMinimalProvider.java:108)
	at org.gradle.api.internal.provider.TransformBackedProvider.calculateOwnValue(TransformBackedProvider.java:82)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateValue(AbstractMinimalProvider.java:108)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.withFinalValue(AbstractMinimalProvider.java:164)
	at org.gradle.api.internal.provider.DefaultProperty.finalValue(DefaultProperty.java:133)
	at org.gradle.api.internal.provider.DefaultProperty.finalValue(DefaultProperty.java:26)
	at org.gradle.api.internal.provider.AbstractProperty.finalizeNow(AbstractProperty.java:245)
	at org.gradle.api.internal.provider.AbstractProperty.beforeRead(AbstractProperty.java:239)
	at org.gradle.api.internal.provider.AbstractProperty.calculateOwnValue(AbstractProperty.java:135)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.getOrNull(AbstractMinimalProvider.java:98)
	at org.gradle.api.internal.provider.ProviderResolutionStrategy$1.resolve(ProviderResolutionStrategy.java:27)
	at org.gradle.util.internal.DeferredUtil.unpack(DeferredUtil.java:59)
	at org.gradle.util.internal.DeferredUtil.unpackOrNull(DeferredUtil.java:49)
	at org.gradle.api.internal.tasks.properties.InputParameterUtils.prepareInputParameterValue(InputParameterUtils.java:38)
	at org.gradle.api.internal.tasks.properties.InputParameterUtils.prepareInputParameterValue(InputParameterUtils.java:30)
	at org.gradle.api.internal.tasks.execution.TaskExecution.lambda$visitRegularInputs$1(TaskExecution.java:315)
	at org.gradle.internal.execution.impl.DefaultInputFingerprinter$InputCollectingVisitor.visitInputProperty(DefaultInputFingerprinter.java:103)
	at org.gradle.api.internal.tasks.execution.TaskExecution.visitRegularInputs(TaskExecution.java:313)
	at org.gradle.internal.execution.impl.DefaultInputFingerprinter.fingerprintInputProperties(DefaultInputFingerprinter.java:63)
	at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionStateWithOutputs(CaptureStateBeforeExecutionStep.java:123)
	at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$captureExecutionState$1(CaptureStateBeforeExecutionStep.java:82)
	at org.gradle.internal.execution.steps.BuildOperationStep$1.call(BuildOperationStep.java:37)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
	at org.gradle.internal.execution.steps.BuildOperationStep.operation(BuildOperationStep.java:34)
	at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionState(CaptureStateBeforeExecutionStep.java:76)
	at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$execute$0(CaptureStateBeforeExecutionStep.java:70)
	at java.base/java.util.Optional.map(Optional.java:260)
	at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:70)
	at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:45)
	at org.gradle.internal.execution.steps.SkipEmptyWorkStep.executeWithNonEmptySources(SkipEmptyWorkStep.java:177)
	at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:86)
	at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:53)
	at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:32)
	at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:21)
	at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
	at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:36)
	at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:23)
	at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:75)
	at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:41)
	at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:32)
	at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:287)
	at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
	at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:21)
	at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
	at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
	at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:47)
	at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:34)
	at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:64)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:146)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:135)
	at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
	at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
	at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:337)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:324)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:317)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 20, 2024
quaff added a commit to quaff/spring-boot that referenced this issue Feb 21, 2024
A task must not use any Project objects at execution time. This includes calling Task.getProject() while the task is running.

See https://docs.gradle.org/7.0/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution

Fix spring-projectsGH-39635
quaff added a commit to quaff/spring-boot that referenced this issue Feb 22, 2024
A task must not use any Project objects at execution time. This includes calling Task.getProject() while the task is running.

See https://docs.gradle.org/7.0/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution

Fix spring-projectsGH-39635
@wilkinsona wilkinsona added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Feb 22, 2024
@wilkinsona
Copy link
Member

Closing in favor of #39644.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
@wilkinsona
Copy link
Member

Unfortunately, I was too quick to close this in favor of #39644 as I cannot reproduce the problem. That means there's no way of knowing if the PR will fix it.

With a basic app generated from start.spring.io, running build with the configuration cache enabled succeeds:

$ ./gradlew --configuration-cache --console=plain build 
Calculating task graph as no cached configuration is available for tasks: build
> Task :processTestResources NO-SOURCE
> Task :processResources
> Task :compileJava
> Task :classes
> Task :resolveMainClassName
> Task :jar
> Task :compileTestJava
> Task :testClasses
> Task :bootJar
> Task :assemble
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
> Task :test
> Task :check
> Task :build

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 3s
7 actionable tasks: 7 executed
Configuration cache entry stored.

Running the same build again then successfully reuses the configuration cache:

$ ./gradlew --configuration-cache --console=plain --rerun-tasks build 
Reusing configuration cache.
> Task :processTestResources NO-SOURCE
> Task :processResources
> Task :compileJava
> Task :classes
> Task :resolveMainClassName
> Task :jar
> Task :compileTestJava
> Task :testClasses
> Task :bootJar
> Task :assemble
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
> Task :test
> Task :check
> Task :build

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 2s
7 actionable tasks: 7 executed
Configuration cache entry reused.

@alexisgayte we're back to needing a minimal sample to be able to make any progress here. Please start with a basic Gradle project generated on start.spring.io, make any amendments to it that are necessary to reproduce the problem and then share the project with us.

@wilkinsona wilkinsona reopened this Feb 27, 2024
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed status: superseded An issue that has been superseded by another labels Feb 27, 2024
@alexisgayte
Copy link
Author

alexisgayte commented Feb 27, 2024

I know, I spent some time already to try to reproduce it locally, and I couldn't. I tried to tweak https://github.com/spring-guides/gs-spring-boot.

My guess is that somehow the gradle cache clean or don't populate bootJar.getManifest().getAttributes().get("Start-Class").

And the hack describe here failed :

	Provider<String> manifestStartClass = project
		.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
	bootJar.getMainClass()
		.convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent()
				? manifestStartClass : resolveMainClassName.get().readMainClassName()));
				

It happens on a kubernetes env during a build process.
It works with gradle 7.x but doesn't with 8.x.
the build uses config cache and some tasks have been previously cached.

this build runs without test "-x check"
./gradlew clean build publish --info -x check

in theory it should fail with only one build before but it could have some cache:
./gradlew clean build

It is linked to the fact we use publish and attach the tasks to the artifact :
https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#publishing-your-application.maven-publish

publishing {
	publications {
		bootJava(MavenPublication) {
			artifact tasks.named("bootJar")
		}
	}
	repositories {
		maven {
			url 'https://repo.example.com'
		}
	}
}

The best way probably to reproduce this issue, now that I understand a bit better what happen would be to create a task that call directly "resolveMainClassName.get().readMainClassName()".
This one should fail.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 27, 2024
@wilkinsona
Copy link
Member

The information about how you're configuring publishing was one missing piece in the puzzle. I can reproduce the failure, or at least one similar to it, with this build.gradle:

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.2.3'
	id 'io.spring.dependency-management' version '1.1.4'
	id 'maven-publish'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
	sourceCompatibility = '17'
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
	useJUnitPlatform()
}

publishing {
	publications {
		bootJava(MavenPublication) {
			artifact tasks.named("bootJar")
		}
	}
	repositories {
		maven {
			url 'file:./repo'
		}
	}
}

publish fails:

$ ./gradlew --configuration-cache --rerun-tasks --console=plain publish                                                                                                 
Calculating task graph as configuration cache cannot be reused because file 'build.gradle' has changed.
> Task :compileJava
> Task :processResources
> Task :classes
> Task :resolveMainClassName
> Task :bootJar
> Task :generatePomFileForBootJavaPublication
> Task :publishBootJavaPublicationToMavenRepository
> Task :publish

FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache problems found in this build.

10 problems were found storing the configuration cache, 5 of which seem unique.
- Task `:bootJar` of type `org.springframework.boot.gradle.tasks.bundling.BootJar`: execution of task ':bootJar' caused invocation of 'Task.project' in other task at execution time which is unsupported.
  See https://docs.gradle.org/8.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:generatePomFileForBootJavaPublication` of type `org.gradle.api.publish.maven.tasks.GenerateMavenPom`: cannot serialize object of type 'org.gradle.api.artifacts.Configuration' as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.5/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:generatePomFileForBootJavaPublication` of type `org.gradle.api.publish.maven.tasks.GenerateMavenPom`: cannot serialize object of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer', a subtype of 'org.gradle.api.artifacts.ConfigurationContainer', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.5/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:generatePomFileForBootJavaPublication` of type `org.gradle.api.publish.maven.tasks.GenerateMavenPom`: cannot serialize object of type 'org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler', a subtype of 'org.gradle.api.artifacts.dsl.DependencyHandler', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.5/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:generatePomFileForBootJavaPublication` of type `org.gradle.api.publish.maven.tasks.GenerateMavenPom`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.5/userguide/configuration_cache.html#config_cache:requirements:disallowed_types

See the complete report at file:///Users/awilkinson/Downloads/gh-39635/build/reports/configuration-cache/9v93z10ucwvvy5e9hr6lye051/a11n9vokcaae0blbrhg5hwpr5/configuration-cache-report.html
> Execution of task ':bootJar' caused invocation of 'Task.project' by task ':resolveMainClassName' at execution time which is unsupported.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
6 actionable tasks: 6 executed
Configuration cache entry discarded with 10 problems.

The dependency management plugin doesn't support the configuration cache. It can be removed and replaced with Gradle's platform support:

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.2.3'
	id 'maven-publish'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
	sourceCompatibility = '17'
}

repositories {
	mavenCentral()
}

dependencies {
	implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
	implementation 'org.springframework.boot:spring-boot-starter'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
	useJUnitPlatform()
}

publishing {
	publications {
		bootJava(MavenPublication) {
			artifact tasks.named("bootJar")
		}
	}
	repositories {
		maven {
			url 'file:./repo'
		}
	}
}

With this configuration, not only are the pom-related problems caused by the dependency management plugin resolved, but the problem with :bootJar is resolved too:

$ ./gradlew --configuration-cache --rerun-tasks --console=plain publish
Calculating task graph as no cached configuration is available for tasks: publish
> Task :generatePomFileForBootJavaPublication
> Task :processResources
> Task :compileJava
> Task :classes
> Task :resolveMainClassName
> Task :bootJar
> Task :publishBootJavaPublicationToMavenRepository
> Task :publish

BUILD SUCCESSFUL in 1s
6 actionable tasks: 6 executed
Configuration cache entry stored.

Are you using the dependency management plugin? If you're not, I'm not sure that we're really much closer to understanding the problem.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 27, 2024
@alexisgayte
Copy link
Author

No, I am using the BOM_COORDINATES.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 27, 2024
@alexisgayte
Copy link
Author

I could reproduce it locally,
I am not sure if that make the difference but my task graph is a bit different:

Task :generateGitProperties
Task :processResources
Task :classes
Task :resolveMainClassName
Task :bootJar
Task :bootStartScripts
Task :bootDistTar
Task :bootDistZip
Task :jar
Task :startScripts
Task :distTar
Task :distZip
Task :sourcesJar
Task :assemble
Task :build
Task :generatePomFileForBootJavaPublication
Task :publishBootJavaPublicationToMavenRepository
Task :publish

Notice the generatePomFileForBootJavaPublication that happen just before the publish.

@wilkinsona
Copy link
Member

I can see that you must have the application plugin applied. You haven't mentioned this before. However, adding that to my attempt to reproduce the problem does not make a difference.

Please share your project where you've been able to reproduce the problem.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 27, 2024
@alexisgayte
Copy link
Author

alexisgayte commented Feb 27, 2024

it seems that the issue is due to the use of a plugin to populate the publishing.

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.2.3'
	id 'my.plugin.MavenPublish' version '1.0.0-SNAPSHOT'
}

dependencies {

	implementation platform("org.springframework.boot:spring-boot-dependencies:3.2.3")
	// tag::actuator[]
	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	// end::actuator[]
	implementation 'org.springframework.boot:spring-boot-starter-web'
	// tag::tests[]
	testImplementation('org.springframework.boot:spring-boot-starter-test')
	// end::tests[]
}

publishing {
	publications {
		bootJava(MavenPublication) {
			artifact tasks.named("bootJar")
		}
	}
}

With my.plugin.MavenPublish being :

plugins {
    id 'maven-publish'
}

publishing {
    repositories {
        maven {
            url = "url"
            credentials {
                username = ""
                password = ""
            }
        }
    }
}

That somehow pushes the generatePomFileForBootJavaPublication task after, I believe this behaviour break the order
and the population of 'bootJar.getManifest().getAttributes().get("Start-Class"));'

Task :build
Task :generatePomFileForBootJavaPublication
Task :publishBootJavaPublicationToMavenRepository
Task :publish

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 27, 2024
@wilkinsona
Copy link
Member

Unfortunately, I still can't reproduce this in the way that you have described. Moving the publishing configuration into a separate plugin does not affect the ordering. I have also tried manually adding a depends on relationship:

tasks.named('generatePomFileForBootJavaPublication') {
	dependsOn tasks.named('build')
}

This does change the ordering but does not reproduce the problem.

Your latest example does not use the application plugin but earlier output showed that it was being used. I also tried with the application plugin applied but it did not reproduce the problem.

Rather than providing small and varying snippets of your build configuration, can you please provide a complete example so that we can unzip it, run a single command, and reproduce the problem?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 29, 2024
@alexisgayte
Copy link
Author

Yes sure, you are right the order is not the issue.
the application is not needed to failed it only the publish.

Can you give me your project? I will try to reproduce it.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 29, 2024
@wilkinsona
Copy link
Member

wilkinsona commented Feb 29, 2024

Given that you have a project that reproduces the problem and I do not, I don't think mine's going to help. Please share a minimal version of yours.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 29, 2024
@alexisgayte
Copy link
Author

no worries, unfortunately my project is not shareable.
I will cut my position here. This issue seems to be not that easy to reproduce or understand.

For anyone that face this issue,
Whatever the underlining issue is, this issue is linked to the call to an unauthorised method. Altho I definitely agree this call should not be expected due to the previous "if condition".

as initially suggested monkey patch ResolveMainClassName works for me.
As describe here : https://github.com/spring-projects/spring-boot/pull/39644/files
There is a risk that doesn't work as expected due to the fact we pull it from a previously cached variable.

side note "org.springframework.boot:spring-boot-loader-tools:3.x.x" would need to be imported for monkey patching it.

@wilkinsona
Copy link
Member

This will hopefully be addressed by #40463.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
@wilkinsona wilkinsona added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Apr 22, 2024
@alexisgayte
Copy link
Author

alexisgayte commented Jun 4, 2024

Thanks for your time and effort on this issue.

Retrying some senaries :

  • with gradle 8.5, spring boot 3.2.6, pipeline docker VM.
    Kept the patches
    all fine

  • with gradle 8.5, spring boot 3.2.6, pipeline docker VM.
    Remove the patches
    all fine

  • with gradle 8.5 spring boot 3.2.5 pipeline docker VM.
    Remove the patches.
    Failed as expected :
    xx:xx:xx 2 problems were found storing the configuration cache, 1 of which seems unique.
    xx:xx:xx - Task :bootJar of type org.springframework.boot.gradle.tasks.bundling.BootJar: execution of task ':bootJar' caused invocation of 'Task.project' in other task at execution time which is unsupported.

  • with gradle 8.7, spring boot 3.2.6, pipeline docker VM.
    It seems to fail before at bootBuildInfo.
    Configuration cache state could not be cached: field writeLock of org.springframework.util.function.SingletonSupplier bean found in field creationTime of org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties bean found in field properties of task :bootBuildInfo of type org.springframework.boot.gradle.tasks.buildinfo.BuildInfo: error writing value of type 'java.util.concurrent.locks.ReentrantLock'
    XX:XX:00 > Unable to make field private final java.util.concurrent.locks.ReentrantLock$Sync java.util.concurrent.locks.ReentrantLock.sync accessible: module java.base does not "opens java.util.concurrent.locks" to unnamed module @XXXXXXX

TLDR: Bug fixed but new bug with gradle 8.7 probably not linked to it.

Edit bug already referenced and ??fixed?? : #40911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
4 participants