diffplug / diffplug/spotless

[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
Dominant language
Java
Stars
5.6k
Forks
559
Avg merge
1d 13h
Merged PRs (30d)
34

Description

**Environment:**

- Java
- Spotless Maven Plugin

**Background**
Our project contains both new and legacy Java files:

- **New files** contain only the new license header:
```java
// New License Header
```
- **Legacy files** contain multiple historical license headers, for example:
```java
// New License Header

// Old License Header
```

**Problem**
When configuring Spotless with:

```xml

${project.basedir}/tools/spotless/license-header.txt
package |import |module

```

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.