GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — disable license rule for specific file · Issue #650 · diffplug/spotless

disable license rule for specific file #650

New issue
Copy link
New issue
Copy link
Closed
#3011
#990
Closed
disable license rule for specific file#650
#3011
#990
Copy link
Labels
enhancement

Description

@marekdef
marekdef
opened on Jul 23, 2020
Issue body actions

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

Reacted by Ji Sungbin

Activity

  1. nedtwigg
    changed the title [-]how to disable license rule for specific file[/-] [+]disable license rule for specific file[/+] on Jul 23, 2020
  2. nedtwigg
    added
    enhancement
    on Jul 23, 2020
  3. nedtwigg commented on Jul 23, 2020

    @nedtwigg
    nedtwigg
    on Jul 23, 2020
    Member
    More actions

    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.

    spotless/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java

    Line 171 in 43e4e97

    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
      }
    }
  4. marekdef commented on Jul 24, 2020

    @marekdef
    marekdef
    on Jul 24, 2020
    Author
    More actions

    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

    Reacted by Ned Twigg
  5. nedtwigg commented on Sep 12, 2020

    @nedtwigg
    nedtwigg
    on Sep 12, 2020
    Member
    More actions

    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.

  6. nedtwigg
    closed this as completedin #990on Dec 1, 2021
  7. nedtwigg commented on Dec 1, 2021

    @nedtwigg
    nedtwigg
    on Dec 1, 2021
    Member
    More actions

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

  8. nedtwigg
    added a commit that references this issue on Aug 15, 2026

    multi license headers in maven-plugin (#3011 closes #650 closes #872)

    This issue will close once commit 705f549 is merged into the 'main' branch.
    705f549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.