I have unit tests for my custom plugins that use projects created using ProjectBuilder. I can apply my plugins and confirm that the configuration they provide has occurred. Now I would like to actually execute one or more tasks, but cannot figure out how to do that.
If I try this:
Project project = ProjectBuilder.builder().withName("testProject").build() Project subProject = ProjectBuilder.builder().withName("testSubProject").withParent(project).build() project.apply plugin: 'my-custom-plugin-that-applies-the-java-plugin-to-subprojects' ... various asserts ... subProject.tasks["build"].execute()
the result of the call to execute() is:
18:01:09.185 [main] DEBUG o.g.a.i.t.e.ExecuteAtMostOnceTaskExecuter - Starting to execute task ':testSubProject:build' 18:01:09.185 [main] INFO o.g.a.i.t.e.SkipTaskWithNoActionsExecuter - Skipping task ':testSubProject:build' as it has no actions. 18:01:09.189 [main] DEBUG o.g.a.i.t.e.ExecuteAtMostOnceTaskExecuter - Finished executing task ':testSubProject:build'
What step am I missing such that ‘build’ has no actions?
If I change to execute ‘build’ on the parent project:
then the task is not even found:
org.gradle.api.UnknownTaskException: Task with name 'build' not found in root project 'testProject'. at org.gradle.api.internal.tasks.DefaultTaskCollection.createNotFoundException(DefaultTaskCollection.java:96) at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:183) at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getAt(DefaultNamedDomainObjectCollection.java:195) at org.gradle.api.internal.tasks.DefaultTaskCollection.getAt(DefaultTaskCollection.java:35) at org.gradle.api.tasks.TaskCollection$getAt.call(Unknown Source)
yet at the command line I can execute ‘gradle build’ on a top-level project that is configured using my plugins.