Skip to content

Provide a mechanism to configure the source sets to which Java Format is applied #425

Open
@jzheaux

Description

@jzheaux

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 check work.

Spring JavaFormat seems to scan the AOT-generated directories for formatting and checkstyle issues resulting in the following error on a vanilla AOT project that also uses JavaFormat:

...
  * build/generated/aotSources/org/springframework/boot/autoconfigure/ssl/SslProperties__BeanDefinitions.java
   * build/generated/aotSources/org/springframework/boot/autoconfigure/ssl/SslAutoConfiguration__BeanDefinitions.java
   * build/generated/aotSources/org/springframework/boot/autoconfigure/availability/ApplicationAvailabilityAutoConfiguration__BeanDefinitions.java
   * build/generated/aotSources/org/springframework/context/event/DefaultEventListenerFactory__BeanDefinitions.java
   * build/generated/aotSources/org/springframework/context/event/EventListenerMethodProcessor__BeanDefinitions.java
   * build/generated/aotSources/org/springframework/aop/framework/autoproxy/InfrastructureAdvisorAutoProxyCreator__BeanDefinitions.java
  
  Run `format` to fix.

Running checkFormat is not ideal against AOT sources since they don't follow the formatting guidelines. Also, I don't need to ensure that they follow my checkstyle rules.

I can fix this by disabling the corresponding tasks:

	tasks.matching { it.name == 'checkFormatAot' }.all { task ->
		task.enabled = false
	}

	tasks.matching { it.name == 'checkFormatAotTest' }.all { task ->
		task.enabled = false
	}

	tasks.matching { it.name == "checkstyleAot" }.all { task ->
		task.enabled = false
	}

	tasks.matching { it.name == "checkstyleAotTest" }.all { task ->
		task.enabled = false
	}

It seems the ideal would be that these tasks not exist, but I'm not sure what is reasonable to change.

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions