本地扫描maven项目依赖jar的license信息
添加plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<!--指定输出内容的模版,方便采集梳理-->
<fileTemplate>/Users/aaa/your_dir/third-party-file.ftl</fileTemplate>
</configuration>
<executions>
<execution>
<goals>
<goal>add-third-party</goal>
</goals>
</execution>
</executions>
</plugin>
ftl模版
这里主要是通过 | 符号来分隔 各个字段方便excel导入
<#--
#%L
License Maven Plugin
%%
Copyright (C) 2012 Codehaus, Tony Chemit
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Lesser Public License for more details.
You should have received a copy of the GNU General Lesser Public
License along with this program. If not, see
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
<#-- To render the third-party file.
Available context :
- dependencyMap a collection of Map.Entry with
key are dependencies (as a MavenProject) (from the maven project)
values are licenses of each dependency (array of string)
- licenseMap a collection of Map.Entry with
key are licenses of each dependency (array of string)
values are all dependencies using this license
-->
<#function licenseFormat licenses>
<#assign result = ""/>
<#list licenses as license>
<#assign result = result + license + " "/>
</#list>
<#return result>
</#function>
<#function artifactFormat p>
<#if p.name?index_of('Unnamed') > -1>
<#return "|" + p.artifactId + "|" + p.groupId + "|" + p.artifactId + "|\"" + p.version + "\"|" + (p.url!"no url defined")>
<#else>
<#return "|" + p.name + "|" + p.groupId + "|" + p.artifactId + "|\"" + p.version + "\"|" + (p.url!"no url defined")>
</#if>
</#function>
<#if dependencyMap?size == 0>
<#else>
license| name|groupId| artifactId|version|url
<#list dependencyMap as e>
<#assign project = e.getKey()/>
<#assign licenses = e.getValue()/>
${licenseFormat(licenses)} ${artifactFormat(project)}
</#list>
</#if>
在项目根目录执行命令
通过outputDirectory参数,把所有输出文件汇集到一起,通过thirdPartyFilename参数,区分不同module的文件命名
mvn license:add-third-party -Dlicense.outputDirectory=/your_directory -Dlicense.thirdPartyFilename=project-name-'${project.artifactId}'.txt
posted on 2024-03-18 10:26 mindSucker 阅读(146) 评论(0) 编辑 收藏 举报