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

Task 'spotlessApply' not found in project ':api'. #27

Closed
fokkoru opened this issue Sep 26, 2024 · 9 comments · Fixed by #30
Closed

Task 'spotlessApply' not found in project ':api'. #27

fokkoru opened this issue Sep 26, 2024 · 9 comments · Fixed by #30
Labels
bug Something isn't working question Further information is requested

Comments

@fokkoru
Copy link

fokkoru commented Sep 26, 2024

It doesn’t work for me, giving the error: Task 'spotlessApply' not found in project ':api'. This error is correct because I set Spotless only for the root module, and it works with Gradle. I’m not sure why it requires adding the task to all modules.

@lipiridi
Copy link
Owner

Hello @fokkoru!
Did you apply the plugin for subprojects?

subprojects {
    apply(plugin = "com.diffplug.spotless")
}

What exact task you are running: for the file or entire project?

@fokkoru
Copy link
Author

fokkoru commented Oct 1, 2024

Hey @lipiridi
Nope, I applied the Spotless plugin only to the root project, so when I run ./gradlew spotlessApply, it formats the code for all projects. I’m also using the IntelliJ IDEA Spotless Gradle plugin and it works as well.

So, the question is: do we really need to apply com.diffplug.spotless to all subprojects, or is applying it just to the root project enough?

@lipiridi
Copy link
Owner

lipiridi commented Oct 1, 2024

@fokkoru thanks for the answer.
The thing is, submodules can have different format configurations.
If a project has submodules, when you run the 'Reformat Project' command, it asks which module the task should be executed on. There’s also an option for the 'Root project.' So your case ideally should be covered. Do you see that modal window?
image

@lipiridi lipiridi added bug Something isn't working question Further information is requested labels Oct 1, 2024
@fokkoru
Copy link
Author

fokkoru commented Oct 1, 2024

Yes, I see the window when I use 'Reformat Project,' but I need the option to reformat a single file. I want to use Action on Save, but in that case, it throws an error.

@lipiridi
Copy link
Owner

lipiridi commented Oct 1, 2024

Now I see your point. It's fair.
So, we need to check the plugin presence in the submodule build file because I don't really want to add a new flag to the settings.
I'll try to do it soon.

@lipiridi
Copy link
Owner

lipiridi commented Oct 5, 2024

@fokkoru Hi again! I was working on the new flow, and while testing, I realized that Spotless from the root project isn't applying changes to the submodules. If it's not included in the submodule plugins, it doesn't work - neither by the plugin nor by manually running the task. Could you share your Gradle build snippets?

@fokkoru
Copy link
Author

fokkoru commented Oct 8, 2024

Hmm, maybe it’s because I’m using target.

Here’s how my root project looks:

plugins {
    kotlin("jvm") version "2.0.20" apply false
    kotlin("kapt") version "2.0.20" apply false
    id("com.diffplug.spotless") version "6.25.0"
}

spotless {
    kotlin {
        target("**/src/**/*.kt", "**/src/**/*.kts")
        ktfmt().dropboxStyle().configure { opt -> opt.setMaxWidth(150) }
    }
    kotlinGradle {
        target("*.gradle.kts", "**/*.gradle.kts")
        ktfmt().dropboxStyle().configure { opt -> opt.setMaxWidth(150) }
    }
    java {
        target("**/src/**/*.java")
        removeUnusedImports()
        palantirJavaFormat()
    }
}

@lipiridi
Copy link
Owner

Yeah, this is it. I had a default target("src/*/java/**/*.java")
So I'm going to prepare the PR

@lipiridi
Copy link
Owner

Version 1.1.3 was released. Will be available in the marketplace during 2 business days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants