-
Notifications
You must be signed in to change notification settings - Fork 488
Description
See https://github.com/diffplug/spotless/tree/main/plugin-gradle#-spotless-plugin-for-gradle
This issue, unlike #700, is solely focused on using Spotless for copyright headers.
In snippets below, make sure to replace [[[ RELEVANT BRANCH ]]] and [[[ START DATE ]]] with the correct information.
spotless {
if (project.hasProperty("spotlessFrom")) {
if (project.spotlessFrom == "ALL") {
println "[Spotless] Ratchet deactivated"
}
else {
println "[Spotless] Ratchet from $project.spotlessFrom"
ratchetFrom project.spotlessFrom
}
}
else if (isCiServer) {
println "[Spotless] CI detected without explicit branch, not enforcing check"
enforceCheck false
}
else {
String spotlessBranch = "origin/[[[ RELEVANT BRANCH ]]]"
println "[Spotless] Local run detected, ratchet from $spotlessBranch"
ratchetFrom spotlessBranch
}
java {
target '**/*.java'
licenseHeaderFile('codequality/spotless/licenseSlashstarStyle.txt')
removeUnusedImports()
}
}It relies on the -PspotlessFrom to activate spotless on specific CI jobs, since spotless otherwise needs a full checkout of the project (in order to compare the commit with the relevant base branch).
We can update the checkout action of an existing job and add spotless as a separate step in order to make failures stand out. That would avoid an extra job, which counts towards CI limits.
Let's assume we have a check job that has checkout,java,gradle checks steps. We configure the checkout step to now checkout everything and add a spotless step configured to "ratchet from" the base branch of the PR right before the existing gradle step:
#ASSUMING THIS JOB EXISTS:
check:
name: other checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
#ADD: with:
fetch-depth: 0#ASSUMING NOW THERE'S A STEP TO CONFIGURE JAVA LIKE:
- uses: actions/setup-java@v1
with:
java-version: 8
#ADD: - uses: eskatos/gradle-command-action@v1
name: gradle
with:
arguments: spotlessCheck -PspotlessFrom=origin/${{ github.base_ref }}
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true#ASSUMING NOW THERE IS A check GRADLE STEP LIKE:
- uses: eskatos/gradle-command-action@v1
name: other tests
with:
arguments: check -x :reactor-core:test --no-daemon
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: trueThe license file includes two line returns, which will enforce a single blank line by Spotless:
/*
* Copyright (c) $YEAR VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Spotless interprets the $YEAR variable correctly in the face of ranges, updating the end year of the range but not the start year (2017-2018 -> 2017-2021). If a single past year is present, Spotless will add the current year as end of the range (2017 -> 2017-2021).
TODO:
- core: [build] Use Spotless plugin to enforce/update copyright headers reactor-core#2729 and [chores] Revert copyright start year + polish reactor-core#2732
- pool: [build] Use Spotless plugin to enforce/update copyright headers reactor-pool#143 and Refine spotless configuration and copyright ranges reactor-pool#144
- reactor-addons
- netty: [build] Switch to Spotless plugin for license check reactor-netty#1705
- reactor-kafka
- reactor-rabbitmq
- reactor-kotlin-extensions
- mention spotless in CONTRIBUTING.md
- (bot) Add Spotless and copyright notice headers spring-attic/reactor-bot#19
- (BOM)
- (site) Introduce Spotless and update copyright notice headers projectreactor.io#68