faster -PspotlessIdeHook with configure-on-demand

Open
#1,101 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
build-system

Research direction

Start in plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java at the referenced lines, then review how Gradle settings evaluation and project descriptors represent nested children. Compare the current spotlessApply -PspotlessIdeHook invocation with the proposed leading-colon and --configure-on-demand form. Done means the IDE hook evaluates only the root and the project owning the target file, including nested projects.

Written by the indexing model from the issue text.

Description

enhancement

Right now, the IDE hook works like this

spotlessApply -PspotlessIdeHook=${ABSOLUTE_PATH_TO_FILE}

But for large multiproject projects we could make it significantly faster with (note the leading colon)

:spotlessApply -PspotlessIdeHook=${ABSOLUTE_PATH_TO_FILE} --configure-on-demand

but only if we modified this code https://github.com/diffplug/spotless/blob/48723eb15b3e6b0ada0841bd78e4dd271af9507f/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtensionImpl.java#L54-L56

by adding something like:

if (project == rootProject) {
  String ideHookPath = (String) project.property(IdeHook.PROPERTY);
  project.gradle.settingsEvaluated { settings -> 
    // the code below works only for root with children, needs to also handle children with children
    ProjectDescriptor owningProject = null;
    ProjectDescriptor rootDescriptor = settings.rootProject
    for (ProjectDescriptor child : rootDescriptor.children) {
      if (ideHookPath.startsWith(child.projectDir.absolutePath)) {
        owningProject = child;
      } 
    }
    if (owningProject != null) {
      project.evaluationDependsOn(owningProject.path)
    }
  }
}

In this way we can avoid evaluating all the spotlessApply tasks and instead only evaluate the root project and, if necessary, the project which contains the file in question.

Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.