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

JavaFormat format task should work with AOT projects #424

Closed
jzheaux opened this issue Sep 25, 2024 · 1 comment
Closed

JavaFormat format task should work with AOT projects #424

jzheaux opened this issue Sep 25, 2024 · 1 comment

Comments

@jzheaux
Copy link

jzheaux commented Sep 25, 2024

If I create a project that uses io.spring.javaformat and also the needed Boot and other plugins to support AOT compilation, then ./gradlew check and ./gradlew format fail. This ticket focuses on making ./gradlew format work.

The error is the following:

A problem was found with the configuration of task ':formatMain' (type 'Format').
  - Gradle detected a problem with the following location: '/home/jzheaux/tmp/javaformat-aot/src/main/java'.
    
    Reason: Task ':compileJava' uses this output of task ':formatMain' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':formatMain' as an input of ':compileJava'.
      2. Declare an explicit dependency on ':formatMain' from ':compileJava' using Task#dependsOn.
      3. Declare an explicit dependency on ':formatMain' from ':compileJava' using Task#mustRunAfter.

You can see this by running ./gradlew format on the linked sample.

I can fix it by following the instructions from the Gradle error:

compileJava {
    dependsOn("formatMain")
}
compileTestJava {
    dependsOn("formatTest")
}

This isn't ideal, though, since I'd prefer to be able to run format and check independently from one another.

For additional context, this comes up in the Spring Security Samples project, where we use JavaFormat to keep the samples uniform. When we recently added an AOT sample, we ran into this behavior.

@wilkinsona
Copy link
Contributor

I think this is really a duplicate of #425. Just as, ideally, Java Format wouldn't check AOT generated source, I also think that it shouldn't bother formatting it either. It feels like we need a mechanism by which Java Format can ignore the aot source set entirely.

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

2 participants