Licensee终极 Gradle 许可证验证插件保护你的项目免受许可证污染【免费下载链接】licenseeGradle plugin which validates the licenses of your dependency graph match what you expect项目地址: https://gitcode.com/gh_mirrors/lic/licenseeLicensee 是一款强大的 Gradle 插件能够自动验证项目依赖图中的许可证是否符合预期防止许可证污染风险。无论是开源项目还是商业应用都能通过 Licensee 轻松管理依赖许可证确保项目合规性。为什么需要 Licensee想象一下你的闭源产品依赖于 Apache 2.0 许可的组件implementation com.example:example:1.0当你升级到新版本后-implementation com.example:example:1.0 implementation com.example:example:1.1这个新版本可能引入了 GPL 许可的依赖这与闭源产品不兼容。你可能在依赖树差异中看到了新依赖但你检查过它的许可证吗---- com.example:example:1.0 --- com.example:example:1.1 \--- com.other:other:2.5使用 Licensee 插件你只需简单配置允许的许可证licensee { allow(Apache-2.0) }此时构建会立即失败并提示 Task :app:licensee FAILED com.other:other:2.5 - SPDX identifier GPL-3.0-or-later is NOT allowed危机轻松化解快速开始3 步集成 Licensee 第 1 步添加插件依赖在项目的build.gradle中添加buildscript { repositories { mavenCentral() } dependencies { classpath app.cash.licensee:licensee-gradle-plugin:1.14.1 } } apply plugin: app.cash.licensee第 2 步应用支持的平台插件Licensee 需要与以下任一插件配合使用java-library/javacom.android.application/com.android.libraryorg.jetbrains.kotlin.jvm/org.jetbrains.kotlin.js/org.jetbrains.kotlin.multiplatform第 3 步配置允许的许可证licensee { allow(Apache-2.0) // 允许 Apache 2.0 许可证 allow(MIT) // 允许 MIT 许可证 }核心功能详解 自动依赖图扫描插件会自动遍历整个传递依赖图因此只需应用到叶子模块如应用程序和服务。对于库项目则应应用到每个库模块。灵活的许可证管理SPDX 许可证标识符使用 SPDX 标准标识符允许常见许可证licensee { allow(Apache-2.0) allow(MIT) allow(BSD-3-Clause) }完整的 SPDX 许可证列表可在 spdx.org/licenses/ 查看。自定义许可证 URL对于非 SPDX 标准的许可证可以直接允许其 URLlicensee { allowUrl(https://example.com/custom-license.html) { because 公司内部自定义许可证兼容 Apache-2.0 } }特定依赖豁免对于缺少或错误许可证信息的依赖可以单独允许licensee { allowDependency(com.jetbrains, annotations, 16.0.1) { because Apache-2.0但许可证 URL 存在拼写错误新版本已修复 } }强大的忽略机制忽略内部/商业依赖licensee { // 忽略整个组 ignoreDependencies(com.mycompany.internal) { because 内部闭源库 } // 忽略特定组件 ignoreDependencies(com.example.sdk, sdk) { because 商业 SDK已购买许可 } }传递依赖忽略危险但有时必要的功能可忽略整个依赖树分支licensee { ignoreDependencies(com.other.sdk, sdk) { transitive true because 商业 SDK 及其依赖 } }详细报告生成插件会在构建目录下生成报告文件artifacts.json包含依赖图中每个组件的许可证信息的 JSON 文件。validation.txt纯文本报告显示每个组件及其许可证是否被允许。报告默认生成位置常规项目buildDir/reports/licenseeAndroid 项目buildDir/reports/licensee/variant name/Android 资产集成对于 Android 项目可以将许可证报告打包到 APK 资产中licensee { bundleAndroidAsset true androidAssetReportPath licenses/artifacts.json // 自定义路径 }报告将可通过assets/licenses/artifacts.json访问。高级使用技巧 开发版本使用如需使用开发快照版本添加快照仓库buildscript { repositories { mavenCentral() maven { url https://central.sonatype.com/repository/maven-snapshots/ } } dependencies { classpath app.cash.licensee:licensee-gradle-plugin:1.15.0-SNAPSHOT } }任务集成licensee任务会自动添加为check任务的依赖确保每次构建都进行许可证验证。对于 Android 和 Kotlin 多平台项目会为每个变体生成特定任务如licenseeDebug。许可证数据更新运行updateLicenses任务可更新嵌入的 SPDX 许可证数据./gradlew updateLicenses总结Licensee 提供了简单而强大的方式来保护你的项目免受许可证冲突的风险。通过自动化依赖许可证验证流程它让开发者可以专注于功能开发同时确保项目合规性。无论是小型开源项目还是大型商业应用Licensee 都是管理依赖许可证的理想选择。LicenseCopyright 2021 Square, Inc. 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 http://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.【免费下载链接】licenseeGradle plugin which validates the licenses of your dependency graph match what you expect项目地址: https://gitcode.com/gh_mirrors/lic/licensee创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考