Skip to content

Commit 6644ecf

Browse files
Manage license headers via spotless
For package-info.java and module-info.java files, the plain java group does not work. Therefore, an additional "javaMisc" formatting group was defined with the sole purpose of these files.
1 parent a9b843b commit 6644ecf

27 files changed

Lines changed: 58 additions & 0 deletions

build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ nmcp {
3535
}
3636

3737
spotless {
38+
val licenseHeader = "${rootProject.rootDir}/gradle/license-header.java"
39+
3840
java {
3941
target("**/src/**/*.java")
42+
licenseHeaderFile(licenseHeader).updateYearWithLatest(true)
4043

4144
// NOTE: decided not to upgrade Google Java Format, as versions 1.29+ require running it on Java 21
4245
googleJavaFormat("1.28.0")
@@ -45,6 +48,15 @@ spotless {
4548
lineEndings = LineEnding.UNIX
4649
}
4750

51+
format("javaMisc") {
52+
target("**/src/**/package-info.java", "**/src/**/module-info.java")
53+
54+
// License headers in these files are not formatted with standard java group, so we need to use custom settings.
55+
// The regex is designed find out where the code starts in these files, so the license header can be placed
56+
// before it. The code starts with either "package", "import", "module" or "/**" in case of a global JavaDoc.
57+
licenseHeaderFile(licenseHeader, "^(package|import|module|/\\*\\*)").updateYearWithLatest(true)
58+
}
59+
4860
kotlin {
4961
target("**/src/**/*.kt")
5062

gradle/license-header.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2025-$YEAR The Problem4J Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in all
11+
* copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
* SOFTWARE.
20+
*/
21+

src/main/java/io/github/problem4j/core/AbstractProblem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.io.Serializable;

src/main/java/io/github/problem4j/core/AbstractProblemBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.io.Serializable;

src/main/java/io/github/problem4j/core/AbstractProblemContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.io.Serializable;

src/main/java/io/github/problem4j/core/AbstractProblemMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.lang.reflect.Field;

src/main/java/io/github/problem4j/core/Problem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.net.URI;

src/main/java/io/github/problem4j/core/ProblemBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.net.URI;

src/main/java/io/github/problem4j/core/ProblemBuilderImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
final class ProblemBuilderImpl extends AbstractProblemBuilder {

src/main/java/io/github/problem4j/core/ProblemContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
* SOFTWARE.
2020
*/
21+
2122
package io.github.problem4j.core;
2223

2324
import java.util.Map;

0 commit comments

Comments
 (0)