A license header manager for Gradle.
Its goal is to ensure that the source files contains a predefined license header determined by some rules, and optionally generate them automatically with a Gradle task.
For a project you need to apply the plugin to your project:
plugins {
id 'org.quiltmc.gradle.licenser' version '1.0.+'
}
The following mavens also need to be added to your settings.gradle
for resolution:
pluginManagement {
repositories {
mavenCentral()
maven {
name 'Quilt'
url 'https://maven.quiltmc.org/repository/release'
}
}
}
Name | Description |
---|---|
applyLicenses |
Updates the license headers in the selected source files. |
checkLicenses |
Verifies the license headers for the selected source files. |
The plugin can be configured using the license
extension on the project.
license {
// Add a license header rule, at least one must be present.
rule file("codeformat/HEADER")
// Exclude/include certain file types: (Default: Excludes files without standard comment format and binary files)
include '**/*.java' // Apply license header ONLY to Java files
// OR
exclude '**/*.properties' // Apply license header NOT to properties files
}
More configuration options may come in the future.
The way this plugin works is a license header have multiple header rules. This allows to select and apply specific headers for some files.
An example file can be found in this repository: codeformat/HEADER
.
A license header rule contains the license header text, and metadata prefixed with ;;
.
License header text can contain variables formatted as the following ${VARIABLE}
.
This would give a file:
License text ${YEAR}
;;metadata: hello
;;more metadata: hi!
;;key: value
Currently, only the ${YEAR}
variable is available.
match_from
No default value.
Regular expressions the file can match against to select this header rule. Each declaration ofmatch_from
is added to the global regex with an OR relation. The regular expression only match against the beginning of the file.year_display
Default value:latest_only
Describes how the year variable should look like.
Available values are:latest_only
for only the last modification year,list
for a list of years,lenient_range
for a range between the absolute minimum year and last modification year
year_selection
Default value:project
Describes how the modification year should be fetched, Git commits are used to determine the last modification year.
Available values are:project
for which the project is used as reference,file
for which each file can have its own last modification year