跳至主要內容

ihub-copyright

Henry...大约 2 分钟

ihub-copyright

插件说明

ihub-copyright插件是版权插件,基于Spotlessopen in new window实现自动为源代码添加或更新版权信息。支持Java、Groovy、Kotlin等语言,可通过Gradle任务自动执行,并可集成到Git Hooks中。

信息描述
插件IDpub.ihub.plugin.ihub-copyright
插件名称版权插件
插件类型Project[1]
扩展名称iHubCopyright
插件依赖ihub-base

插件安装

Kotlin
plugins {
    id("pub.ihub.plugin.ihub-copyright")
}

配置示例

版权配置文件

  1. 通过COPYRIGHT文件配置版权信息,文件放置在项目根目录下:
Copyright (c) 2025 the original author or authors.

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.
  1. 通过LICENSE文件提取版权信息,目前支持识别:
    • Apache License
    • MIT License

扩展配置

Kotlin
iHubCopyright {
    // 是否启用IDEA版权配置(默认:true)
    enableIdea.set(true)
}

可用任务

插件基于Spotless提供以下任务:

任务说明
spotlessApply自动为源代码添加/更新版权头
spotlessCheck检查源代码是否包含正确的版权头

集成Git Hooks

当与iHubGitHooks插件配合使用时,可以在提交代码前自动执行版权检查:

Kotlin
plugins {
    id("pub.ihub.plugin.ihub-copyright")
    id("pub.ihub.plugin.ihub-git-hooks")
}

iHubGitHooks {
    hooks.set(mapOf(
        "pre-commit" to "./gradlew spotlessCheck"
    ))
}

支持的语言

  • Java
  • Groovy
  • Kotlin

自动排除**/generated/**目录下的生成代码。


  1. Project:项目类型插件,配置于build.gradle文件,类型说明详见open in new window ↩︎