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

There is no formatter for 'java' files Installed #362

Open
overfullstack opened this issue Jul 25, 2023 · 3 comments
Open

There is no formatter for 'java' files Installed #362

overfullstack opened this issue Jul 25, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@overfullstack
Copy link

overfullstack commented Jul 25, 2023

Getting this pop-up when trying to format Java files

image
  • VS Code version: 1.81.0-insider
  • Gradle version: 8.2.1
  • Java version: 17.0.5
  • Gradle for Java extension: v3.12.7

Spotless Settings in VS Code:

"java.format.enabled": false,
"files.trimTrailingWhitespace": false,
"spotlessGradle.diagnostics.enable": true,
"spotlessGradle.format.enable": true,
"editor.codeActionsOnSave": {
  "source.fixAll.spotlessGradle": true
},
"[java]": {
  "editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
},
"[kotlin]": {
  "editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
},
"[kotlinGradle]": {
  "editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
}

Sample Project: https://github.com/overfullstack/ds-algo
Spotless Config: https://github.com/overfullstack/ds-algo/blob/master/buildSrc/src/main/kotlin/ds-algo.root-conventions.gradle.kts#L26

spotless {
  lineEndings = PLATFORM_NATIVE
  kotlin {
    ktfmt().googleStyle()
    target("**/*.kt")
    trimTrailingWhitespace()
    endWithNewline()
    targetExclude("**/build/**", "**/.gradle/**", "**/generated/**")
  }
  kotlinGradle {
    ktfmt().googleStyle()
    target("**/*.gradle.kts")
    trimTrailingWhitespace()
    endWithNewline()
    targetExclude("**/build/**", "**/.gradle/**", "**/generated/**")
  }
  java {
    toggleOffOn()
    target("**/*.java")
    importOrder()
    removeUnusedImports()
    googleJavaFormat()
    trimTrailingWhitespace()
    indentWithSpaces(2)
    endWithNewline()
    targetExclude("**/build/**", "**/.gradle/**", "**/generated/**")
  }
  format("xml") {
    targetExclude("pom.xml")
    target("*.xml")
    eclipseWtp(XML)
  }
  format("documentation") {
    target("*.md", "*.adoc")
    trimTrailingWhitespace()
    indentWithSpaces(2)
    endWithNewline()
  }
}

This has a mix of both Kotlin and Java

  • ./gradlew spotlessDiagnose --no-configuration-cache succeeds and Spotless is setup correctly as ./gradlew spotlessApply works as expected
@overfullstack overfullstack added the bug Something isn't working label Jul 25, 2023
@itizarsa
Copy link

@badsyntax Would you be able to check this? If you're occupied, could you guide me to setup this locally & try fixing it?

@artiz
Copy link

artiz commented Jun 24, 2024

Similar issue for me, wehn I try to format Java sources with "richardwillis.vscode-spotless-gradle" I receive error:

Extension 'Spotless Gradle' is configured as formatter but it cannot format 'Java'-files

My config:

"[java]": {
        "editor.defaultFormatter": "richardwillis.vscode-spotless-gradle",
        "spotlessGradle.format.enable": true,
        "spotlessGradle.diagnostics.enable": true,
        "editor.codeActionsOnSave": {
          "source.fixAll.spotlessGradle": "always"
        }
    },
    "[gradle]": {
      "editor.defaultFormatter": "richardwillis.vscode-spotless-gradle",
      "spotlessGradle.diagnostics.enable": true,
      "spotlessGradle.format.enable": true
    },
    ...

Command line ./gradlew spotlessApply works fine

@itizarsa
Copy link

I had multiple gradle versions installed on my machine, when I faced this issue. I removed all except one version, the issue is gone. Not sure why that's a problem.

I used sdkman to install multiple versions.

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

No branches or pull requests

4 participants