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

Spotless uses afterEvaluate #506

Closed
asaikali opened this issue Jan 9, 2020 · 18 comments
Closed

Spotless uses afterEvaluate #506

asaikali opened this issue Jan 9, 2020 · 18 comments
Labels

Comments

@asaikali
Copy link

asaikali commented Jan 9, 2020

Spotless plugin is generating a deprecation warning with Gradle 6.0.1

Using method Project#afterEvaluate(Action) when the project is already evaluated has been deprecated. This will fail with an error in Gradle 7.0. The configuration given is ignored because the project has already been evaluated. To apply this configuration, remove afterEvaluate.

I am configuring spotless from a within the buildSrc folder for all projects that apply the java plugin

├── buildSrc
│   ├── build.gradle.kts
│   ├── settings.gradle.kts
│   └── src
│       └── main
│           └── kotlin
│               ├── java-library-conventions.gradle.kts
│               └── java-test-fixtures-conventions.gradle.kts

java-library-conventions.gradle.kts contains

plugins {
    `java-library`
    jacoco
    checkstyle
    id("com.diffplug.gradle.spotless")
    id("com.gorylenko.gradle-git-properties")
}
/// omitted stuff 
spotless {
    java {
        googleJavaFormat()
    }
}

The buildSrc/build.gradle.kts contains

plugins {
    `kotlin-dsl`
}

repositories {
    gradlePluginPortal()
}

dependencies {
    implementation("com.diffplug.spotless:spotless-plugin-gradle:3.27.0" )
    implementation("gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:2.2.0")
}

full stack trace for the warning from gradle 6.0.1 and spotless 3.27.0

> Configure project :app
Using method Project#afterEvaluate(Action) when the project is already evaluated has been deprecated. This will fail with an error in Gradle 7.0. The configuration given is ignored because the project has already been evaluated. To apply this configuration, remove afterEvaluate.
	at org.gradle.api.internal.project.DefaultProject.maybeNagDeprecationOfAfterEvaluateAfterProjectIsEvaluated(DefaultProject.java:1019)
	at org.gradle.api.internal.project.DefaultProject.afterEvaluate(DefaultProject.java:1000)
	at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:48)
	at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:26)
	at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:43)
	at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:51)
	at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:181)
	at org.gradle.api.internal.plugins.DefaultPluginManager.access$300(DefaultPluginManager.java:51)
	at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:276)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
	at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:159)
	at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:156)
	at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:156)
	at org.gradle.api.internal.plugins.DefaultPluginManager.addImperativePlugin(DefaultPluginManager.java:88)
	at org.gradle.api.internal.plugins.DefaultPluginManager.addImperativePlugin(DefaultPluginManager.java:95)
	at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:72)
	at com.diffplug.gradle.spotless.SpotlessExtension.<init>(SpotlessExtension.java:66)
	at com.diffplug.gradle.spotless.SpotlessExtension_Decorated.<init>(Unknown Source)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator.newInstance(AsmBackedClassGenerator.java:200)
	at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:402)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstanceWithDisplayName(DependencyInjectingInstantiator.java:50)
	at org.gradle.internal.extensibility.DefaultConvention.instantiate(DefaultConvention.java:216)
	at org.gradle.internal.extensibility.DefaultConvention.create(DefaultConvention.java:125)
	at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:35)
	at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:26)
	at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:43)
	at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:51)
	at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:181)
	at org.gradle.api.internal.plugins.DefaultPluginManager.access$300(DefaultPluginManager.java:51)
	at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:276)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
	at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:159)
	at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:156)
	at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:156)
	at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:136)
	at org.gradle.kotlin.dsl.precompile.v1.PrecompiledProjectScript$plugins$1.id(PrecompiledScriptTemplates.kt:154)
	at org.gradle.kotlin.dsl.precompile.v1.PrecompiledProjectScript$plugins$1.id(PrecompiledScriptTemplates.kt:131)
	at Java_library_conventions_gradle$1.invoke(java-library-conventions.gradle.kts:5)
	at Java_library_conventions_gradle$1.invoke(java-library-conventions.gradle.kts:1)
	at org.gradle.kotlin.dsl.precompile.v1.PrecompiledProjectScript.plugins(PrecompiledScriptTemplates.kt:153)
	at Java_library_conventions_gradle.<init>(java-library-conventions.gradle.kts:1)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at JavaLibraryConventionsPlugin.apply(JavaLibraryConventionsPlugin.kt:12)
	at JavaLibraryConventionsPlugin.apply(JavaLibraryConventionsPlugin.kt:6)
	at org.gradle.api.internal.plugins.ImperativeOnlyPluginTarget.applyImperative(ImperativeOnlyPluginTarget.java:43)
	at org.gradle.api.internal.plugins.RuleBasedPluginTarget.applyImperative(RuleBasedPluginTarget.java:51)
	at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:181)
	at org.gradle.api.internal.plugins.DefaultPluginManager.access$300(DefaultPluginManager.java:51)
	at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:276)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
	at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:159)
	at org.gradle.api.internal.plugins.DefaultPluginManager$2.execute(DefaultPluginManager.java:156)
	at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:156)
	at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:127)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$4.run(DefaultPluginRequestApplicator.java:167)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:231)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:163)
	at org.gradle.kotlin.dsl.provider.PluginRequestsHandler.handle(PluginRequestsHandler.kt:48)
	at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost.applyPluginsTo(KotlinScriptEvaluator.kt:184)
	at Program.execute(Unknown Source)
	at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator.evaluate(KotlinScriptEvaluator.kt:110)
	at org.gradle.kotlin.dsl.provider.KotlinScriptPluginFactory$create$1.invoke(KotlinScriptPluginFactory.kt:51)
	at org.gradle.kotlin.dsl.provider.KotlinScriptPluginFactory$create$1.invoke(KotlinScriptPluginFactory.kt:36)
	at org.gradle.kotlin.dsl.provider.KotlinScriptPlugin.apply(KotlinScriptPlugin.kt:34)
	at org.gradle.configuration.BuildOperationScriptPlugin$1$1.run(BuildOperationScriptPlugin.java:69)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
	at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:66)
	at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:63)
	at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:49)
	at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:63)
	at org.gradle.configuration.project.BuildScriptProcessor$1.run(BuildScriptProcessor.java:45)
	at org.gradle.internal.Factories$1.create(Factories.java:26)
	at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:212)
	at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:193)
	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:42)
	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
	at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:35)
	at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject$1.run(LifecycleProjectEvaluator.java:107)
	at org.gradle.internal.Factories$1.create(Factories.java:26)
	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
	at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
	at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withProjectLock(DefaultProjectStateRegistry.java:238)
	at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:232)
	at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.withMutableState(DefaultProjectStateRegistry.java:193)
	at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.run(LifecycleProjectEvaluator.java:96)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:68)
	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:699)
	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:142)
	at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:36)
	at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:64)
	at org.gradle.configuration.DefaultProjectsPreparer.prepareProjects(DefaultProjectsPreparer.java:61)
	at org.gradle.configuration.BuildOperatingFiringProjectsPreparer$ConfigureBuild.run(BuildOperatingFiringProjectsPreparer.java:52)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
	at org.gradle.configuration.BuildOperatingFiringProjectsPreparer.prepareProjects(BuildOperatingFiringProjectsPreparer.java:40)
	at org.gradle.initialization.DefaultGradleLauncher.prepareProjects(DefaultGradleLauncher.java:204)
	at org.gradle.initialization.DefaultGradleLauncher.doClassicBuildStages(DefaultGradleLauncher.java:142)
	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:130)
	at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:110)
	at org.gradle.internal.invocation.GradleBuildController$1.execute(GradleBuildController.java:60)
	at org.gradle.internal.invocation.GradleBuildController$1.execute(GradleBuildController.java:57)
	at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:85)
	at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:78)
	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
	at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
	at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:78)
	at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:57)
	at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:31)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
	at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
	at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:39)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:51)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:45)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:50)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
	at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:78)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
	at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:42)
	at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:28)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:52)
	at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:59)
	at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:36)
	at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:68)
	at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:38)
	at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:37)
	at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:26)
	at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
	at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:60)
	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:41)
	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:48)
	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:32)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:68)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:27)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
	at org.gradle.util.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.base/java.lang.Thread.run(Thread.java:834)
@nedtwigg
Copy link
Member

nedtwigg commented Jan 9, 2020

I'm using Gradle 6.0.1 myself, but I haven't seen this warning so far. At some point, you must say something like apply from: 'java-library-conventions.gradle.kts'. My guess is that you're doing something like this:

afterEvaluate {
  if (hasPlugin(Java)) {
    apply from: 'java-library-conventions.gradle.kts'
  }
}

The afterEvaluate in Spotless would be hard to avoid. It would be nice if Gradle allowed some kind of trampolining so that afterEvaluates could compose with each other, but it looks like that's not their plan for now...

@asaikali
Copy link
Author

asaikali commented Jan 10, 2020

I tried to create a simple single project with spotless with no child modules but I did not see the deprecation warning. My project is multi module project below is an example of one of the modules is configured.

plugins {
    `java-library-conventions`
    `java-test-fixtures-conventions`
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.flywaydb:flyway-core")
    runtimeOnly("org.postgresql:postgresql")
} 

Rather than using the root project to configure the child projects I created my own plugin in the buildSrc similar to what junit does

The root project is tiny it only looks like this.

subprojects {
    repositories {
        mavenCentral()
    }
    group = "com.example"
    version = "1.0.0" 
}

I hope this helps.

@nedtwigg
Copy link
Member

nedtwigg commented Jan 10, 2020

I think that confirms that my comment above is a correct diagnosis. This line in the junit buildSrc would cause this.

https://github.com/junit-team/junit5/blob/8dfcee3207d982db1a7bb2a11b44cd4f4a7a1116/buildSrc/src/main/kotlin/java-library-conventions.gradle.kts#L271-L272

This might be why junit has kept spotless outside of this plugin:

https://github.com/junit-team/junit5/blob/abb6fdcb12a71a395aefff8d76a4ee756bfaa7d4/build.gradle.kts#L121-L141

You can definitely configure spotless inside your plugin if you want. You just can't do it inside an afterEvaluate block. FWIW, I think this is a feature-deficiency in Gradle - it seems like it should be possible to trampoline afterEvaluate calls so that this would not be a problem (though I might be wrong). So I think your paths forward are either

  1. don't configure Spotless inside an afterEvaluate block
  2. see if you can get Gradle to enhance afterEvaluate

Also, we just launched blowdryer, which has been really helpful to us internally for structuring our build scripts. If you have multiple git repositories, I think it's a lot better than the buildSrc plugin route. We haven't started marketing it yet, but we just shipped 1.0

@asaikali
Copy link
Author

I don't have AfterEvaluate in my plugin below is the complete java-library-conventions.gradle.kts

plugins {
    `java-library`
    jacoco
    checkstyle
    id("com.diffplug.gradle.spotless")
    id("com.gorylenko.gradle-git-properties")
}

val developmentOnly by configurations.creating // used by spring boot devtools
configurations {

    // don't allow version conflicts for production code
    compileClasspath {
        resolutionStrategy.failOnVersionConflict()
    }
    runtimeClasspath {
        extendsFrom(developmentOnly)
        resolutionStrategy.failOnVersionConflict()
    }

    // don't allow version conflicts for test code
    testCompileClasspath {
        resolutionStrategy.failOnVersionConflict()
    }
    testRuntimeClasspath {
        resolutionStrategy.failOnVersionConflict()
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
    implementation(platform(project(":platform")))
    implementation("org.springframework.boot:spring-boot-starter")
    api("com.google.guava:guava")
    testImplementation("nl.jqno.equalsverifier:equalsverifier")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
}

tasks.test {
    useJUnitPlatform()
    finalizedBy("jacocoTestReport")
}

tasks.jacocoTestReport {
    reports {
        xml.isEnabled = true
        xml.destination = file("${buildDir}/jacoco/test.xml")
        html.isEnabled = true
        html.destination = file("${buildDir}/jacoco/html")
    }
}

tasks.jacocoTestCoverageVerification {
    violationRules {
        rule {
            limit {
                minimum = "0.1".toBigDecimal()
            }
        }
    }
}

tasks.compileJava {
    options.compilerArgs.add(element = "-parameters");
}

checkstyle {
    toolVersion = "8.28"
    configDirectory.set(rootProject.file("src/checkstyle"))
    isShowViolations = true
    maxErrors = 0
    maxWarnings = 0
    isIgnoreFailures = false
}

spotless {
    java {
        googleJavaFormat()
        @Suppress("INACCESSIBLE_TYPE")
        licenseHeaderFile("${rootDir}/src/spotless/masteryway.license.java")
    }
}

@nedtwigg
Copy link
Member

But how do you apply this plugin? Search java-library-conventions.gradle.kts throughout all your .gradle files, and trace where it gets called. I suspect one of them is called within an afterEvaluate. Another possibility might be if you're applying this script from a different project. e.g. if :foo is applying Spotless to :bar after :bar has already finished its configuration. If it's this latter case, you should be able to fix with evaluationDependsOn.

@nedtwigg nedtwigg changed the title Spotless 3.27.0 plugin is generating a deprercation warning with Gradle 6.0.1 Spotless uses afterEvaluate Jan 12, 2020
@nedtwigg
Copy link
Member

Found anything interesting?

@nedtwigg
Copy link
Member

I'm closing due to inactivity, but not due to lack of curiosity! If you ever find anything interesting about what was happening here, I hope you'll come back and tell us what you find.

@eskatos
Copy link
Contributor

eskatos commented Mar 4, 2020

From the stacktrace we can see that SpotlessPlugin creates SpotlessExtension which in its constructor reaches out to the root project to apply the same SpotlessPlugin to it and does afterEvaluate {}. That's this afterEvaluate {} which emit the deprecation message.

https://github.com/diffplug/spotless/blob/gradle/3.27.1/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java#L66

In other words, on multi project builds and when applied to a subproject, the Spotless plugin tries to go up the project hierarchy to the root project, adding an afterEvaluate block to an already evaluated project. This doesn't work and the registered afterEvaluate hook is ignored as said in the warning. This should be fixed and will become an error in Gradle 7 anyway.

@JLLeitschuh JLLeitschuh reopened this Mar 4, 2020
@nedtwigg
Copy link
Member

nedtwigg commented Mar 4, 2020

The same stacktrace as the first comment? If I take that stacktrace, and remove every line that matches at org\.gradle\..*$, then I get this:

> Configure project :app
Using method Project#afterEvaluate(Action) when the project is already evaluated has been deprecated. This will fail with an error in Gradle 7.0. The configuration given is ignored because the project has already been evaluated. To apply this configuration, remove afterEvaluate.
    at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:48)
    at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:26)
    ....
    at com.diffplug.gradle.spotless.SpotlessExtension.<init>(SpotlessExtension.java:66)
    at com.diffplug.gradle.spotless.SpotlessExtension_Decorated.<init>(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    ...
    at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:35)
    at com.diffplug.gradle.spotless.SpotlessPlugin.apply(SpotlessPlugin.java:26)
    ...
    at Java_library_conventions_gradle$1.invoke(java-library-conventions.gradle.kts:5)
    at Java_library_conventions_gradle$1.invoke(java-library-conventions.gradle.kts:1)
    ...
    at Java_library_conventions_gradle.<init>(java-library-conventions.gradle.kts:1)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at JavaLibraryConventionsPlugin.apply(JavaLibraryConventionsPlugin.kt:12)
    at JavaLibraryConventionsPlugin.apply(JavaLibraryConventionsPlugin.kt:6)
    ...

It is true that if you apply Spotless to a subproject, it will automatically apply itself to the root project at the line that you noted - this is purely for dependency resolution reasons (long story). The problem model that you are proposing is this, correct?

root: [evaluating... done]                                      [root.afterEvaluate, WARNING]
sub :     [evaluating... apply Spotless, apply Spotless to root ^                       done.]

If there is an example project which can reliably recreate the race condition above, then I can fix it pretty quickly. I might be wrong, but I don't think it is possible to make the timeline above happen. And that is because even though Gradle can do parallel execution, my understanding is that evaluation/configuration is still single-threaded. So I believe, perhaps mistakenly, that the root project never finishes evaluation until all subprojects have finished evaluation (which is different from execution).

It's easy to prove me wrong - a multi-project build with just a single subproject that applies Spotless, with a big fat sleep can easily make the timeline above happen. Such an integration test would be an important part of ensuring that a fix is actually working. If someone builds the test (any repo that I can clone to reproduce is fine), then I can implement the fix quickly.

I'm not willing to implement or even merge a "fix" without such a testcase, because I suspect (perhaps incorrectly) that you will get the same error after the "fix", because the problem actually lies elsewhere, and building the test will help you see that it is elsewhere, or else it will help me to build/verify a fix :)

@asaikali
Copy link
Author

asaikali commented Mar 4, 2020

Project to reproduce the issue https://github.com/asaikali/spotless-issue

@nedtwigg
Copy link
Member

nedtwigg commented Mar 4, 2020

It's easy to prove me wrong

See, I was right 😝 Thanks for sticking with this.

@JLLeitschuh, this behavior seems like a gradle bug to me, but it's easy to fix in Spotless so I will definitely do so. I interpret the design intent of this deprecation warning as "you cannot call afterEvaluate from within an afterEvaluate block", and although that means that you cannot compose two plugins that each use afterEvaluate, trampolining is tricky and I can understand why gradle might make this choice.

However, I don't think there is anything tricky about adding an "afterEvaluate" block to the root project from a subproject. There are quite a few plugins that use the rootProject as a central caching/coordinating place. It's easy for us to fix, but there might be other cases which are harder.

The biggest argument that this is a gradle bug is that this works:

// build.gradle (root)
subprojects {
  apply plugin: 'com.diffplug.gradle.spotless'
}

But this does not:

// subproject/build.gradle
apply plugin: 'com.diffplug.gradle.spotless'

It's much easier for me to just fix this in Spotless than to shepherd this through Gradle's bug tracker, but figured I'd point it out to you just in case :)

@nedtwigg nedtwigg added bug and removed question labels Mar 4, 2020
nedtwigg added a commit that referenced this issue Mar 5, 2020
nedtwigg added a commit that referenced this issue Mar 5, 2020
@nedtwigg
Copy link
Member

nedtwigg commented Mar 5, 2020

Fixed in 3.27.2. Thanks again for sticking with this bug!

@nedtwigg nedtwigg closed this as completed Mar 5, 2020
@asaikali
Copy link
Author

asaikali commented Mar 5, 2020

Thanks for fixing this issue, your plugin is awesome, and you do all the hard work of keeping it going. Thank you.

@nedtwigg
Copy link
Member

nedtwigg commented Mar 5, 2020

Thanks! I did this particular two-liner, but the community as a whole does a lot more than I do, especially the committer team (@fvgh, @jbduncan, @lutovich, @JLLeitschuh)

@eskatos
Copy link
Contributor

eskatos commented Mar 5, 2020

Thanks for fixing this bug quickly and doing a new release ready for us to use!

FWIW, reproducing the issue outside of the spotless plugin is a two liner:

// settings.gradle
include("sub")
// sub/build.gradle
rootProject.afterEvaluate {}

Running gradle help --warning-mode=all the afterEvaluate {} block is ignored and you get the same deprecation warning:

> Configure project :sub
Using method Project.afterEvaluate(Action) when the project is already evaluated has been deprecated. This will fail with an error in Gradle 7.0. The configuration given is ignored because the project has already been evaluated. To apply this configuration, remove afterEvaluate. Consult the upgrading guide for further information: https://docs.gradle.org/6.2.2/userguide/upgrading_version_5.html#calling_project_afterevaluate_on_an_evaluated_project_has_been_deprecated

Gradle evaluates projects walking down the projects hierarchy, starting with the root project. When the :sub project starts being evaluated, the root project has already been evaluated. Doing project.parent.afterEvaluate {} at any level of a multi-project build hierarchy will have the same effect.

@nedtwigg
Copy link
Member

nedtwigg commented Mar 6, 2020

Doing project.parent.afterEvaluate {} at any level of a multi-project build hierarchy will have the same effect.

if you are using multiple build files. If you're doing a multiproject build with just one file, then you're good:

// settings.gradle
include("sub")

// build.gradle (root)
project(':sub') {
  rootProject.afterEvaluate {}
}

This makes it easy to write an integration test that you think is testing multiproject builds, but actually it isn't. We had/have a multiproject integration test, which is part of why I was so skeptical that this was our bug rather than user error.

@eskatos
Copy link
Contributor

eskatos commented Mar 6, 2020

Yes. This is expected and I agree it can be confusing at first. The project(":sub") {} in the root project script will be executed before sub/build.gradle, so, before the root project is done being evaluated.

@nedtwigg
Copy link
Member

nedtwigg commented Mar 6, 2020

it can be confusing at first

One of the (many) things I admire about Gradle is how it does such a good job "feeling" like a declarative description, rather than a script. It's almost like the only point of the scripting is just to allow you to describe repetitive data in a more concise way than writing it out by hand - beginners can ignore the scripting completely and still be productive.

As a user, once you have used afterEvaluate, you are recognizing that it's a script and not just a declarative data description, so you're mentally prepared for the idea that "you can't do afterEvaluate inside afterEvaluate". The fact that the order in which you apply plugins, and whether they are applied from one file or another, will affect whether or not they can compose without errors, is a deep violation of the useful "declarative" illusion.

Naively, it also seems like it would be easy to fix. I can imagine the implementation advantages of making a project immutable once it has been "evaluated", but "afterEvaluate", being a purely additive operation and not a mutation per-se, seems like it could be easy to tack-on. If the design goal is "calling afterEvaluate from within afterEvaluate is a fuzzy concept, and we should prevent it", that seems noble, but it's different than the limit Gradle is currently enforcing.

Anyway, not a big deal, probably not worth the effort for such a small case, just my final 2cents. Thanks for Gradle, always super impressed by the product and team :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants