Summary of the problem
I recently upgraded the Spotless Gradle plugin in a Java project I work on from 5.1.0 to 5.6.1 and saw an unexpected change in the copyright header. My project uses a license header template with the $YEAR placeholder that I tell Spotless about using licenseHeaderFile. I had made some additional changes to the source file in question and ran ./gradlew spotlessApply to make sure these changes complied with the configured settings for formatting and indentation. I was surprised to see that the year (2020) copyright header had changed to a range. It looks like this happens if the template contains a number that has at least 4 digits (like a street number or a zip code). It seems like #690 which became available in version 5.5.0 may be the reason.
Here's what I did to see if this was the case:
- I undid the changes Spotless had made to the file, downgraded the plugin to
5.4.0 and ran ./gradlew spotlessApply and the copyright header was untouched; I even added an errant space in the header and Spotless fixed that without changing the year in the header
- I undid the changes Spotless made, upgraded the plugin to
5.5.0 and ran ./gradlew spotlessApply and saw the year in the header change to a range
Since the project I was working with is not open source, I worked on putting together a sample project to illustrate the problem. The repository is https://github.com/smoothreggae/spotless-license-header-bug and I have listed the steps to reproduce the problem in README.md
While doing this, I encountered another problem: if a Java source file did not have a copyright header at all and I ran ./gradlew spotlessApply, the spotlessJava task printed out the message "Can't parse copyright year '', defaulting to 2020" before adding the copyright header to the source file. The sample project accounts for this as well.
Is there some other setting that I need to configure now to get this to work like it used to before?
Gradle version
6.6.1
Spotless version
5.5.0
Operating system and version
Windows 10
public repository to demonstrate the problem
https://github.com/smoothreggae/spotless-license-header-bug
Summary of the problem
I recently upgraded the Spotless Gradle plugin in a Java project I work on from
5.1.0to5.6.1and saw an unexpected change in the copyright header. My project uses a license header template with the$YEARplaceholder that I tell Spotless about usinglicenseHeaderFile. I had made some additional changes to the source file in question and ran./gradlew spotlessApplyto make sure these changes complied with the configured settings for formatting and indentation. I was surprised to see that the year (2020) copyright header had changed to a range. It looks like this happens if the template contains a number that has at least 4 digits (like a street number or a zip code). It seems like #690 which became available in version5.5.0may be the reason.Here's what I did to see if this was the case:
5.4.0and ran./gradlew spotlessApplyand the copyright header was untouched; I even added an errant space in the header and Spotless fixed that without changing the year in the header5.5.0and ran./gradlew spotlessApplyand saw the year in the header change to a rangeSince the project I was working with is not open source, I worked on putting together a sample project to illustrate the problem. The repository is https://github.com/smoothreggae/spotless-license-header-bug and I have listed the steps to reproduce the problem in
README.mdWhile doing this, I encountered another problem: if a Java source file did not have a copyright header at all and I ran
./gradlew spotlessApply, the spotlessJava task printed out the message "Can't parse copyright year '', defaulting to 2020" before adding the copyright header to the source file. The sample project accounts for this as well.Is there some other setting that I need to configure now to get this to work like it used to before?
Gradle version
6.6.1
Spotless version
5.5.0
Operating system and version
Windows 10
public repository to demonstrate the problem
https://github.com/smoothreggae/spotless-license-header-bug