Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster -PspotlessIdeHook with configure-on-demand #1101

Open
nedtwigg opened this issue Jan 18, 2022 · 0 comments
Open

faster -PspotlessIdeHook with configure-on-demand #1101

nedtwigg opened this issue Jan 18, 2022 · 0 comments

Comments

@nedtwigg
Copy link
Member

nedtwigg commented Jan 18, 2022

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

@Override
protected void createFormatTasks(String name, FormatExtension formatExtension) {
boolean isIdeHook = project.hasProperty(IdeHook.PROPERTY);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant