https://github.com/kyoripowered/licenser
https://github.com/kyoripowered/licenser
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kyoripowered/licenser
- Owner: KyoriPowered
- License: mit
- Created: 2021-04-18T16:57:27.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-26T19:06:09.000Z (over 3 years ago)
- Last Synced: 2023-02-26T08:55:49.320Z (almost 3 years ago)
- Language: Groovy
- Size: 323 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# licenser
licenser is a simple license header manager for Gradle. It can automatically ensure that the source files contain a predefined license header and optionally generate them automatically using a Gradle task. It provides several options as configuration (e.g. variables in the license header, included file types, style of license header) so it can be customized for each project.
## Features
- Apply pre-defined license header in a file to the source files of the source sets or any other set of files (configurable)
- Variable substitution in the license header file
- Apply license header only to certain files (include/exclude possible)
- Apply special license headers to matching files
- Support for Android projects
## Usage
For a simple project you only need to apply the licenser plugin to your project:
```gradle
plugins {
id 'org.cadixdev.licenser' version '0.6.1'
}
```
This will apply the `LICENSE` file found in the project directory to all common source file types known to licenser.
## Tasks
|Name|Description|
|----|-----------|
|`checkLicenses`|Verifies the license headers for the selected source files.|
|`updateLicenses`|Updates the license headers in the selected source files. Will create a backup in `build/tmp/updateLicense/original`.|
|`checkLicense`|Verifies the license headers for the specified source set.|
|`updateLicense`|Updates the license headers in the specified source set. Will create a backup in `build/tmp/updateLicense/original`.|
|`checkLicenseAndroid`|Same as `checkLicense`, but for Android source sets.|
|`updateLicenseAndroid`|Same as `updateLicense`, but for Android source sets.|
|`checkLicenseCustom`|Same as `checkLicense`, but for custom tasks.|
|`updateLicenseCustom`|Same as `updateLicense`, but for custom tasks.|
|`licenseCheck`|Alias for `checkLicenses`|
|`licenseFormat`|Alias for `updateLicenses`|
## Configuration
The plugin can be configured using the `license` extension on the project.
- **Custom header file source:** (Default: `LICENSE` in project directory)
```gradle
license {
header = project.file('HEADER.txt')
}
```
- **Variable substitution in the license header:**
```gradle
license {
header = project.file('HEADER.txt')
properties {
name = 'Company'
year = 2018
}
// Example license header: Copyright (C) ${year} ${name}
}
```
- **Toggle new empty line after the license header:** (Default: true)
```gradle
license {
newLine = false // Disables the new line
}
```
- **Ignore existing license headers:** (Default: false)
```gradle
license {
skipExistingHeaders = true // Ignore existing license headers on files
}
```
- **Exclude/include certain file types:** (Default: Excludes files without standard comment format and binary files)
```gradle
license {
include '**/*.java' // Apply license header ONLY to Java files
// OR
exclude '**/*.properties' // Apply license header NOT to properties files
}
```
- **Apply special license header to some matching files:**
```gradle
license {
// Apply special license header to one source file
matching('**/ThirdPartyLibrary.java') {
header = file('THIRDPARTY-LICENSE.txt')
}
// Apply special license header to matching source files
matching(includes: ['**/thirdpartylibrary/**', '**/ThirdPartyLibrary.java']) {
header = file('THIRDPARTY-LICENSE.txt')
}
}
```
- **Custom tasks: Apply license header to files outside of source set:**
```gradle
license {
tasks {
gradle {
files.from('build.gradle.kts', 'settings.gradle.kts', 'gradle.properties')
// header = ... (optional)
}
directory {
files.from('path/to/directory')
// include/exclude ... (optional)
}
}
}
```
- **Manage file extension to license header styles:**
```gradle
license {
style {
java = 'JAVADOC' // Sets Java license header style to JAVADOC (/**)
}
}
```
- **Other options:**
```gradle
license {
// Ignore failures and only print a warning on license violations
ignoreFailures = true
// Read/write files with platform charset (Default: UTF-8)
charset = Charset.defaultCharset().name()
// Override the line ending used for license files (Default: system line ending)
lineEnding = '\n'
}