GeezerVison is showing github.com — disable license rule for specific file · Issue #650 · diffplug/spotless
disable license rule for specific file #650DescriptionI have some code that has no license or code that is apache licence (like copied from a code sample).
I have also licence rule that add copyright to me, but I do not want to claim copyrights for those/
I tried
@file:Suppress("licenseHeader")
but it seems the license is still overwritten Activitychanged the title [-]how to disable license rule for specific file[/-] [+]disable license rule for specific file[/+] on Jul 23, 2020nedtwigg commented on Jul 23, 2020 I think you're describing a relatively common usecase, which we don't support easily. @file:Suppress("licenseHeader") is a good idea, is there another tool which supports that? If so we'll opt-in to it.
There are a few corner cases, but I think the way to support it would be to look in this string for that "suppress" token, and then return early.
|
beforeYear = licenseHeader.substring(0, yearTokenIndex); |
Happy to take a well-tested PR for this, it's a bit tricky because the license header step has a few different modes.
In the meantime, there is a verbose workaround using multiple language-specific blocks, e.g.:
spotless {
java {
targetExclude 'foo.java'
googleJavaFormat()
licenseHeader ...
}
format 'javaWithoutLicense', com.diffplug.gradle.spotless.JavaExtension, {
target 'foo.java'
googleJavaFormat()
// no licenseHeader
}
}marekdef commented on Jul 24, 2020 well I tried licenseHeader because com.diffplug.spotless.generic.LicenseHeaderStep.NAME
not that I have seen it in other tools.
We use @file:Supress("ForbiddenImport") and it seemed to work but this must be detekt supression nedtwigg commented on Sep 12, 2020 This isn't a good solution, but you can now disable spotless formatting with spotless:off and spotless:on tags. If you make your license header look like this:
/**
* Blah blah
* Blah blah blah blah
*
* Licensing exceptions below:
* spotless:off (none) spotless:on
*/
Then if you replace the stuff inside of (none), including multiple lines, that stuff will be preserved. That's not a good solution, but it's the best we have for now. nedtwigg commented on Dec 1, 2021 Published in plugin-gradle 6.0.1. Currently unsupported in maven, a PR for that is welcome. added a commit that references this issue on Aug 15, 2026This issue will close once commit 705f549 is merged into the 'main' branch.705f549
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|