Suppose I have the following project structure in Eclipse:
For example, I got a sample project, which got all project folders in the same directory (including root project).
{noformat} workspace – project1 – project2 – rootProject {noformat}
rootProject got a settings.gradle file with the following content: {code:title=settings.gradle} includeFlat ‘project1’ includeFlat ‘project2’ {code}
The build.gradle located in the rootProject contains the following: {code:title=build.gradle} subprojects {
task hello << {
println “Hello from “ + project.name
} } {code}
If I build the EclipseProject models for these projects I’d get “hello” task on project1 and on project2 If I build the BuildInvocations models for these projects I’d get only “hello” task selector on the root project.
If I use Gradle Tooling API to launch tasks, namely: org.gradle.tooling.BuildLauncher.forTasks(String… tasks) BuildLauncher is created based on the created ProjectConnection for one of these projects.
Created BuildLauncher for the root project and task argument is “hello” - executes as expected Here is the output :my-lib:hello Hello from my-lib :product:hello Hello from product
BUILD SUCCESSFUL
Total time: 0.108 secs
If I attempt to execute “hello” or “:hello” on the BuildLauncher created based on ProjectConnection to “project1” I get an exception during the build: Caused by: org.gradle.execution.TaskSelectionException: Task ‘hello’ not found in root project ‘project1’. Some candidates are: ‘help’.
at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:71)
at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:52)
at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:44)
at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:46)
at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:40)
at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
at org.gradle.execution.DefaultBuildExecuter.select(DefaultBuildExecuter.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
If I try “:project1:hello” I’d get a build exception informing that “project1” cannot be found in root project “project1” Caused by: org.gradle.execution.taskpath.ProjectFinderByTaskPath$ProjectLookupException: Project ‘project1’ not found in root project ‘project1’.
at org.gradle.execution.taskpath.ProjectFinderByTaskPath.findProject(ProjectFinderByTaskPath.java:47)
at org.gradle.execution.taskpath.TaskPathResolver.resolvePath(TaskPathResolver.java:49)
at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:56)
at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:52)
at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:44)
at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:46)
at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:40)
at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
at org.gradle.execution.DefaultBuildExecuter.select(DefaultBuildExecuter.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
… 47 more
“hello” and “:project1:hello” used to work with Gradle pre 1.12 or pre 1.11
Is task “hello” defined for project1 and project2? We always used EclipseProject and HierarchicalEclipseProject models and just looking into using BuildInvocations model now for Gradle Eclipse 3.6.3. Therefore, previously, we’d show “hello” for project1 and project2 and execute the task as shown above and that was working. Therefore the questions are: 1. Looks like there is a difference between EclipseProject and BuildInvocations model. If yes, which one of them is correct? And when roughly the other model going to be fixed? 2.What’s the recommended way tio launch task “hello”?Is org.gradle.tooling.BuildLauncher.forTasks(String… tasks) still OK to call? Or perhaps it’s best start using forLaunchables(…)?
Thanks in advance.
Cheers, Alex