Skip to content

[question] Is there a way to skip licenseHeader for legacy files while keeping other formatters active? #2908

@bengbengbalabalabeng

Description

@bengbengbalabalabeng

Environment:

  • Java
  • Spotless Maven Plugin

Background
Our project contains both new and legacy Java files:

  • New files contain only the new license header:
    // New License Header
  • Legacy files contain multiple historical license headers, for example:
    // New License Header
    
    // Old License Header

Problem
When configuring Spotless with:

<licenseHeader>
    <file>${project.basedir}/tools/spotless/license-header.txt</file>
    <delimiter>package |import |module </delimiter>
</licenseHeader>

Spotless replaces all license headers in all files, including legacy files that should keep their original headers.

This causes two issues:

  1. Legacy files lose their historical license information
  2. If I exclude legacy files from licenseHeader, then other formatters (googleJavaFormat, eclipse, prettier, idea, tableTestFormatter, importOrder) will also stop applying to them

Expected Behavior

  • New files should receive the new license header
  • Legacy files should keep their existing headers, but still be formatted by other Spotless steps

Question
Is there a recommended way to configure Spotless so that:

  • licenseHeader applies only to new files
  • Other formatters still apply to all files
  • Legacy files are not modified by the license step

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions