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

disable license rule for specific file #650

Closed
marekdef opened this issue Jul 23, 2020 · 4 comments · Fixed by #990
Closed

disable license rule for specific file #650

marekdef opened this issue Jul 23, 2020 · 4 comments · Fixed by #990

Comments

@marekdef
Copy link

I 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

@nedtwigg nedtwigg changed the title how to disable license rule for specific file disable license rule for specific file Jul 23, 2020
@nedtwigg
Copy link
Member

nedtwigg commented 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
Copy link
Author

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
Copy link
Member

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
Copy link
Member

nedtwigg commented Dec 1, 2021

Published in plugin-gradle 6.0.1. Currently unsupported in maven, a PR for that is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants