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

Open
#2,908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java

Research direction

Start with the Maven Spotless configuration and the licenseHeader delimiter shown in the issue, then review how the listed formatting steps are applied to Java files. Determine whether licenseHeader can be limited to new files without excluding the other steps; done means new files receive the header, legacy headers remain unchanged, and all other formatters still run.

Written by the indexing model from the issue text.

Description

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
Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.