[GRADLE-2226] Tooling API: LongRunningOperation.withArguments -P and -D are both not working Created: 12/Apr/12  Updated: 04/Jan/13  Resolved: 16/Apr/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.0-rc-2

Type: Bug
Reporter: Kris De Volder Assignee: Szczepan Faber
Resolution: Fixed Votes: 1


 Description   

I tried to set system and project properties via the tooling API 'withArguments' method.
But it looks like that isn't working.

The arguments seem to be accepted without errors (i.e. when I later run the operation, there are no exceptions), but the properties do not get set.

For system properties this is a relatively minor problem since setting them via setJVMArguments method works.
But I don't know if there is an alternative for project properties.

I tested this with RC1 (both API and Gradle version) with the following simple build script.

task wrapper(type: Wrapper) {
    gradleVersion = '1.0-rc-1'
}
task showProp << {
	println myProp
}

When I do ./gradlew -PmyProp=foo showProp

It works as expected. However when I try to run the same task with the tooling API and use withArguments to pass the same -P argument it gets the following error:

Caused by: org.gradle.api.LocationAwareException: Build file '/tmp/testws/test/build.gradle' line: 5
Execution failed for task ':showProp'.
	at org.gradle.initialization.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:85)
	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:76)
	at org.gradle.tooling.internal.provider.ExecuteBuildAction.run(ExecuteBuildAction.java:43)
	at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:63)
	at org.gradle.launcher.daemon.protocol.Build.run(Build.java:67)
	at org.gradle.launcher.daemon.protocol.Build.run(Build.java:63)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:45)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailureAsResult.execute(CatchAndForwardDaemonFailureAsResult.java:24)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:32)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:112)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:110)
	at org.gradle.util.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:110)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:47)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:48)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:37)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.HandleClientDisconnectBeforeSendingCommand.execute(HandleClientDisconnectBeforeSendingCommand.java:21)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.StopConnectionAfterExecution.execute(StopConnectionAfterExecution.java:22)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:49)
	at org.gradle.launcher.daemon.server.Daemon$1$1.run(Daemon.java:113)
	at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
	... 3 more
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':showProp'.
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:71)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:48)
	at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)
	at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34)
	at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:200)
	at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:172)
	at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
	at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:111)
	at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
	at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)
	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
	at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:243)
	at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:192)
	at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:177)
	at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)
	at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:36)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
	at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
	at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
	at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
	at org.gradle.cache.internal.DefaultCacheAccess$1.create(DefaultCacheAccess.java:111)
	at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)
	at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:109)
	at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:103)
	at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
	at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
	at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
	at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
	at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:152)
	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:108)
	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:76)
	at org.gradle.tooling.internal.provider.ExecuteBuildAction.run(ExecuteBuildAction.java:43)
	at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:63)
	at org.gradle.launcher.daemon.protocol.Build.run(Build.java:67)
	at org.gradle.launcher.daemon.protocol.Build.run(Build.java:63)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:45)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailureAsResult.execute(CatchAndForwardDaemonFailureAsResult.java:24)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:32)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:112)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:110)
	at org.gradle.util.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:110)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:47)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:48)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:37)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:34)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.HandleClientDisconnectBeforeSendingCommand.execute(HandleClientDisconnectBeforeSendingCommand.java:21)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.StopConnectionAfterExecution.execute(StopConnectionAfterExecution.java:22)
	at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
	at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:49)
	at org.gradle.launcher.daemon.server.Daemon$1$1.run(Daemon.java:113)
	at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: groovy.lang.MissingPropertyException: Could not find property 'myProp' on task ':showProp'.
	at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)
	at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:35)
	at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:54)
	at org.gradle.api.DefaultTask_Decorated.getProperty(Unknown Source)
	at build_5sg1iifotv14l0nl4h83qjqna7$_run_closure2.doCall(/tmp/testws/test/build.gradle:5)
	at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:457)
	at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:445)
	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:63)
	... 79 more


 Comments   
Comment by Kris De Volder [ 12/Apr/12 ]

BTW did not include an example of -D use but it seems to suffer from the same problem.

Comment by Kris De Volder [ 12/Apr/12 ]

-b option is also not working.

I run on the command line
./gradlew -b other-build.gradle and get an error that it can't find the 'other-build.gradle' as expected, since I didn't have such build file.

But when I set the same option via tooling api the build runs with the regular build.gradle file and has no error.

I'm starting to suspect that the withArguments simply does not work at all.

Comment by Kris De Volder [ 12/Apr/12 ]

This issue is blocking issues:

Comment by Kris De Volder [ 12/Apr/12 ]

Since I wasn't 100% sure that the options I tried where supposed to work (though I would certainly hope so, as those are likely some of the most useful ones).

I also tried -u which is one of the options that the API docs expclitly mention as one that is supposed to work.
I get the same 'unknown option' error there.

Comment by Szczepan Faber [ 14/Apr/12 ]

Hey Kris,

We had a gap in our integration tests and hence we didn't catch that problem :/ It's because most of our tests run with 'verboseLogging' turned on (a setting on DefaultGradleConnector) and hence some args parsing logic (the logging configuration parsing) was short-circuited. I'm just tightening it and fixing the problem. Thanks for reporting and for patience!

Cheers!

Comment by Szczepan Faber [ 16/Apr/12 ]

The fix has been pushed.

Comment by Kris De Volder [ 16/Apr/12 ]

I just did a quick test with gradle-1.1-rc-1-20120411000100+0200.
I tried setting a property with -P but it is not working.

This is what I get now (see at end of this message).

Is that what is supposed to happen?

Kris

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks: 
[sts]      :showProp
[sts] -----------------------------------------------------
[sts] Build failed
org.gradle.tooling.GradleConnectionException: Could not execute build using Gradle distribution 'http://services.gradle.org/distributions-snapshots/gradle-1.1-rc-1-20120411000100+0200-bin.zip'.
	at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:55)
	at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:81)
	at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)
Caused by: org.gradle.cli.CommandLineArgumentException: Unknown command-line option '-P'.
	at org.gradle.cli.CommandLineParser$BeforeFirstSubCommand.onStartOption(CommandLineParser.java:308)
	at org.gradle.cli.CommandLineParser.parse(CommandLineParser.java:133)
	at org.gradle.cli.AbstractCommandLineConverter.convert(AbstractCommandLineConverter.java:22)
	at org.gradle.tooling.internal.provider.input.AdaptedOperationParameters.getBuildLogLevel(AdaptedOperationParameters.java:72)
	at org.gradle.tooling.internal.provider.DefaultConnection.createExecuter(DefaultConnection.java:126)
	at org.gradle.tooling.internal.provider.DefaultConnection.run(DefaultConnection.java:112)
	at org.gradle.tooling.internal.provider.DefaultConnection.executeBuild(DefaultConnection.java:81)
	at org.gradle.tooling.internal.consumer.connection.AdaptedConnection.executeBuild(AdaptedConnection.java:60)
	at org.gradle.tooling.internal.consumer.connection.LazyConnection$1.run(LazyConnection.java:101)
	at org.gradle.tooling.internal.consumer.connection.LazyConnection.withConnection(LazyConnection.java:119)
	at org.gradle.tooling.internal.consumer.connection.LazyConnection.executeBuild(LazyConnection.java:98)
	at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:58)
	at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection$1.run(ProgressLoggingConnection.java:56)
	at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.run(ProgressLoggingConnection.java:81)
	at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConnection.executeBuild(ProgressLoggingConnection.java:56)
	at org.gradle.tooling.internal.consumer.connection.LoggingInitializerConnection.executeBuild(LoggingInitializerConnection.java:58)
	at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:52)
	at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$1.run(DefaultAsyncConnection.java:50)
	at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$3.run(DefaultAsyncConnection.java:79)
	... 4 more
[sts] Time taken: 0 min, 0 sec
[sts] -----------------------------------------------------
Comment by Szczepan Faber [ 16/Apr/12 ]

Hey Kris!

Sorry I wasn't clear earlier. The snapshot hasn't yet built. I'll build it right away and tell you when it's ready to test.

Cheers!

Comment by Szczepan Faber [ 16/Apr/12 ]

You can try the latest RC snapshot now. Cheers!

Comment by Kris De Volder [ 16/Apr/12 ]

Woohoo. It works!

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks: 
[sts]      :showProp
[sts] -----------------------------------------------------
:showProp
foo

BUILD SUCCESSFUL

Total time: 0.224 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 0 sec
[sts] -----------------------------------------------------

Thanks for the quick response on this issue.

Kris

Generated at Wed Jun 30 12:16:09 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.