-
Notifications
You must be signed in to change notification settings - Fork 459
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
Apply license header to package-info.java
and module-info.java
#532
Comments
package-info.java
and module-info.java
I believe google-java-format is applied to these files, it's only the license header step which is not. spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java Lines 191 to 193 in 45d2122
spotless/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java Lines 39 to 40 in 45d2122
In order to fix this, we would need a smarter delimiter for detecting the start of these files: spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java Lines 47 to 49 in 45d2122
The trick is that we'll need a different delimiter depending on what the filename is. This is possible, but most of our steps are filename-agnostic. WorkaroundYou can do something like this (untested): spotless {
java {
googleJavaFormat("1.7")
licenseHeaderFile "${project.rootDir}/company.license.java"
}
format 'javaMisc', {
target 'src/**/package-info.java', 'src/**/module-info.java'
licenseHeaderFile "${project.rootDir}/company.license.java", 'some-delimiter-i-dont-know-what'
}
} |
I'm actually not sure if google-java-format has any specific support for package-info.java and module-info.java files. A quick search on GitHub suggests that it doesn't crash when formatting module-info.java files and perhaps package-info.java ones as well, but not necessarily that they're formatted neatly or at all, which your experience seems to confirm. Thus I'd suggest that you keep an eye here for module-info.java support. As for package-info.java support, I'm not entirely sure... @nedtwigg I admit I fail to see how your example above would allow (package|module)-info.java files to be formatted with google-java-format. Would you mind clarifying for me? |
Most of our users don't realize that the "steps" are independent - it feels like they're configuring one step. In @jacek99's original example, That's why I focused this issue to say "Spotless does delegate out to your formatter, but it is a known limitation that the license header part will not happen, this is why, and this is how you can fix it or work around it". |
Ahh, okay, I'd completely misunderstood what was happening here; I thought the problem was that google-java-format wasn't being applied to those files by default! Thanks for clarifying @nedtwigg. :) |
Just to confirm that @nedtwigg's workaround works simply by using spotless {
java {
...
}
format 'javaMisc', {
target 'src/**/package-info.java', 'src/**/module-info.java'
licenseHeaderFile rootProject.file('config/spotless.license.java'), 'package '
}
} |
Actually I take that back. It does apply the license, but also remove the Javadoc |
Using |
As best we could tell, there wasn’t a single regex that worked for all cases, you need a full Java parser, which is why it has gone unsupported so long. |
I am using eclipse.xml formatting rules. Any workaround to apply the header to |
We added spotless with the Google Java style:
and it formatted all code...but left all the package-info.java classes untouched when we run spotlessJavaApply
is that expected behaviour or a bug? How can we force the format to include those files as well?
The text was updated successfully, but these errors were encountered: