• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

CadixDev/licenser: A simple license header manager for Gradle

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

CadixDev/licenser

开源软件地址(OpenSource Url):

https://github.com/CadixDev/licenser

开源编程语言(OpenSource Language):

Groovy 90.3%

开源软件介绍(OpenSource Introduction):

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:

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<SourceSet>/original.
checkLicense<SourceSet> Verifies the license headers for the specified source set.
updateLicense<SourceSet> Updates the license headers in the specified source set. Will create a backup in build/tmp/updateLicense<SourceSet>/original.
checkLicenseAndroid<SourceSet> Same as checkLicense<SourceSet>, but for Android source sets.
updateLicenseAndroid<SourceSet> Same as updateLicense<SourceSet>, but for Android source sets.
checkLicenseCustom<Name> Same as checkLicense<SourceSet>, but for custom tasks.
updateLicenseCustom<Name> Same as updateLicense<SourceSet>, 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)

    license {
        header = project.file('HEADER.txt')
    }
  • Variable substitution in the license header:

    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)

    license {
        newLine = false // Disables the new line
    }
  • Ignore existing license headers: (Default: false)

    license {
        skipExistingHeaders = true // Ignore existing license headers on files
    }
  • Exclude/include certain file types: (Default: Excludes files without standard comment format and binary files)

    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:

    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:

    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:

    license {
        style {
            java = 'JAVADOC' // Sets Java license header style to JAVADOC (/**)
        }
    }
  • Other options:

    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'
    }



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap