How to refresh the Gradle Tasks view?

The Gradle Tasks view contains projects from which the gradle nature has been removed, projects which were deleted and sometimes duplicate projects. There is also a case where a valid gradle project has its tasks grayed out:

I tried the “refresh tasks for all projects” button, but it didn’t resolve the issue. How can this view be cleaned?

Happens with Buidship 2.x and Eclipse Neon and oxygen.

The task view reflects the configuration of the Gradle build only, so removing the Gradle nature doesn’t have an effect. You can remove a project by removing it from the Gradle build and then refresh the task view.

Regarding the grayed out tasks, you either have a composite build in your workspace or you encountered a known Buildship issue. Please add your :thumbsup: there so that we know we should priorize the fix.

Thanks for the reply.

How do I do that?

BTW, I found a similar issue on SO: https://stackoverflow.com/questions/41287445/how-to-remove-a-project-from-the-gradle-tasks-view-or-clean-the-view.

Typically subprojects are declared in the settings.gradle file. Just you comment out a subproject and refresh the task view.

FYI Buildship needs all projects from the Gradle build loaded into the workspace. If we didn’t have this requirement we wouldn’t be able to ensure the consistency of the project classpaths. We have plans to add (basic and full) support for partial imports, but that will come later.

I don’t think I understand. If I create a Gradle project it is added to the tasks view. If I then delete the build and settings flies the project remains there. I want it to be removed.

Deleting the .gradle files don’t have an effect because without them your project is still a valid Gradle build. In fact, even an empty directory is a valid Gradle build (try running gradle in an empty folder in the command line).

I would like to clarify the glossary because I’m not sure what exactly you want to achieve. A Gradle build consist of a collection of projects, each of which is imported as an individual Eclipse workspace project (the project creation wizard is only a specialized project importer). Also, the same projects are presented in the task view.

Since Buildship doesn’t support partial imports, this means that you’ll see all the projects from the Gradle build in your workspace and in the tasks view. If you delete a project and then start a synchronization (right-click on another project and select Gradle > Refresh Gradle Project), the deleted project will re-appear in the workspace. The tasks view behaves similarly, except there you can’t even delete a project.

This means you can only remove a project from the tasks view by removing it completely from the build like I suggested above. Or, if you want to remove the entire build, you can either:

  • delete all projects from the workspace that belong to the same Gradle build, or
  • delete the org.eclipse.buildship.core.gradleprojectnature nature from all .project files that belong to the same Gradle build.

Thanks for the clarifications. The project I want to remove is not a part of any build - it is not referenced in any settings.gradle file. Also it was not a subproject or a dependency.

If I create a new Gradle project which is not related to any other project, what are the steps I need to take in order to remove it from the build?

In that case removing the Gradle nature from the project and refreshing the task view should work. I’ve created a small screencast exhibiting this feature.

I am having a similar issue where the Gradle Task List has duplicates Tasks and Categories. I have removed the Gradle nature and reboot the application several times, but it did not clear the issue up. I am using Eclipse Oxygen and there is only a single project with no sub-projects within my workspace.

@hawkeyeflash Can you please post a screenshot here showing the duplicates and the view’s context menu? Something like this:

That’s expected. There are two types of tasks in the view: project tasks and task selectors. Project tasks are executed on exactly one project (e.g. calling ./gradlew :sub:assemble). Tasks selectors are executed on the current project and all of its subprojects (e.g. calling ./gradlew assemble). You can enable/disable each types in the Task view’s menu.

Thanks for this information.