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 error in a multi project using includeFlat in settings.gradle #121

Closed
regrog opened this issue Jun 16, 2017 · 8 comments
Closed
Labels

Comments

@regrog
Copy link

regrog commented Jun 16, 2017

I'm changing my project to use flat dependencies but I'm facing this error.
Gradle 3.5
java 8
spotless 3.4

here an example, projectA is the root project and if you try to build it, you get an error:
spotlessErrorExample.zip

Thanks for the help

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:203)
	at com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull(PluginGradlePreconditions.java:34)
	at com.diffplug.gradle.spotless.SpotlessTask.setTarget(SpotlessTask.java:103)
	at com.diffplug.gradle.spotless.SpotlessTask_Decorated.setTarget(Unknown Source)
	at com.diffplug.gradle.spotless.FormatExtension.setupTask(FormatExtension.java:365)
	at com.diffplug.gradle.spotless.SpotlessPlugin.lambda$createTasks$18(SpotlessPlugin.java:71)
	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
	at com.diffplug.gradle.spotless.SpotlessPlugin.createTasks(SpotlessPlugin.java:67)
	at com.diffplug.common.base.Errors.lambda$wrap$5(Errors.java:218)
	at com.diffplug.common.base.Errors.run(Errors.java:210)
	at com.diffplug.gradle.spotless.SpotlessPlugin.lambda$apply$17(SpotlessPlugin.java:50)
	at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:93)
	at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:82)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:44)
	at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:79)
	at org.gradle.internal.event.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy15.afterEvaluate(Unknown Source)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:82)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:76)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.access$000(LifecycleProjectEvaluator.java:33)
	at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:53)
	at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:50)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:628)
	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:129)
	at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
	at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
	at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
	at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:161)
	at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:158)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:158)
	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
	at org.gradle.initialization.DefaultGradleLauncher.getBuildAnalysis(DefaultGradleLauncher.java:107)
	at org.gradle.launcher.exec.GradleBuildController.configure(GradleBuildController.java:79)
	at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner.run(ClientProvidedBuildActionRunner.java:60)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:43)
	at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:40)
	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
	at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
	at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:75)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
	at org.gradle.util.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)

FAILURE: Build failed with an exception.

* Where:
Build file '/home/andrea/workspace/projectA/projectA.gradle' line: 16

* What went wrong:
A problem occurred evaluating root project 'projectA'.
> /home/andrea/workspace/api/build is not a child of /home/andrea/workspace/projectA
@jbduncan
Copy link
Member

@regrog Thanks for the example project. I was able to reproduce this stack trace on my machine.

I admit that it was my fault that it throws a NullPointerException at that particular point (as I introduced null checks in that portion of the code base not that long ago), but I'm very surprised that null is even being passed to this part of Spotless.

@nedtwigg It seems to me that a particular FormatExtension (I can't tell which yet) is being constructed with a target that contains one or more null elements, which surprises SpotlessTask::setTarget, since it expects all elements to be non-null.

Do you have any further insight as to what may be causing target to contain one or more null elements in the first place?

@fvgh
Copy link
Member

fvgh commented Jun 18, 2017

@regrog Spotless is (currently) not supporting flat hierarchies in combination with wildcard file selection target '**/*.gradle', '**/*.md', '**/.gitignore'.
As you stated in your comment, you see at the end of the build:

/home/andrea/workspace/api/build is not a child of /home/andrea/workspace/projectA

This is an internal spotless exception. @jbduncan Have to debug to see why then a NullPointerException follows...

As a work-around you could configure something like:
target fileTree(dir: project.rootDir, includes: ['**/*.gradle', '**/*.md', '**/.gitignore'], excludes: ['**/build/**'])

@regrog Is this work-around OK for you at the moment? E.g. I think that the underlying code which causes the exception should be changed (I think it's a bug and not a feature 😉 ), but at least I have not time to do it now. Last word on this issue has anyway @nedtwigg .

@regrog
Copy link
Author

regrog commented Jun 19, 2017

@fvgh you work-around works perfectly.
I didn't know that flat hierarchies in combination with wildcard isn't supported yet.

Thanks

@fvgh
Copy link
Member

fvgh commented Jun 19, 2017

@regrog Good to hear that you can continue with your work. We will address the issue soon. Thanks again for your report.

@fvgh
Copy link
Member

fvgh commented Jun 19, 2017

@jbduncan:

As far I understand it, the IllegalArgumentException gets eaten by the surrounding Action.
The SpotlessExtension separates formatter registration and configuration.
So when exceptions during the configuration are eaten, you end up with corrupted formatters.
That lead to the NullPointerException during the setup call.

Well I just walked the code a bit. Maybe you want to have another look. Anyhow, there is definitely a problem in the exception handling which allows the creation of corrupted formatter steps. I think that problem is more severe than the flat hierarchy support.

@nedtwigg
Copy link
Member

I submitted PR #122 which fixes the flat wildcard issue. I agree that the deeper problem is the corrupted formatter steps, but I that's actually a gradle problem, gradle/gradle#874. Looks like they don't see it as a bug at the moment, I'll chime in. They may well have a good reason for the current behavior which isn't immediately obvious.

@nedtwigg
Copy link
Member

Once this CI job completes, this will be fixed in 3.5.0-SNAPSHOT.

@nedtwigg
Copy link
Member

Released in 3.4.1.

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