首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用license-maven-plugin

如何使用license-maven-plugin
EN

Stack Overflow用户
提问于 2014-03-21 11:20:45
回答 3查看 9.8K关注 0票数 10

我想使用license-maven-plugin以便能够为我的项目生成许可证头。

因此,我有以下pom.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.foo</groupId>
    <artifactId>bar-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>Bar: Parent</name>

    <licenses>
        <license>
            <name>Apache 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>

    <organization>
        <name>My Corp.</name>
        <url>http://www.mycorp.org/</url>
    </organization>

    <inceptionYear>2014</inceptionYear>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <license.licenseName>apache_v2</license.licenseName>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>1.6</version>

                    <configuration>
                        <verbose>false</verbose>
                        <includes>
                            <includes>**/*.java</includes>
                        </includes>
                    </configuration>

                    <executions>
                        <execution>
                            <id>generate-license-headers</id>
                            <goals>
                                <goal>update-file-header</goal>
                            </goals>
                            <phase>process-sources</phase>
                            <configuration>
                                <licenseName>Apache 2.0</licenseName>
                                <roots>
                                    <root>src/main/java</root>
                                    <root>src/test/java</root>
                                </roots>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    ...
</project>

我从命令行调用以下代码:

代码语言:javascript
复制
mvn license:update-file-header

这一切都通过了,但是我的license头看起来像这样:

代码语言:javascript
复制
/*
 * #%L
 * Bar: Foo
 * %%
 * Copyright (C) 2014 My Corp.
 * %%
 * 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.
 * #L%
 */

显然,我不想在我的license头中使用#%L%%#L%。我需要设置什么才能去掉它们?

EN

回答 3

Stack Overflow用户

发布于 2016-09-09 16:48:26

如另一个答案所示,这些标记是查找和更新许可证信息所必需的。你可以做的一件事就是让它们不那么烦人。

在我的项目中,我已经将它们更改为更漂亮的东西:

代码语言:javascript
复制
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>license-maven-plugin</artifactId>
    <version>1.9</version>
    <configuration>
        <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
        <processStartTag>========================LICENSE_START=================================</processStartTag>
        <processEndTag>=========================LICENSE_END==================================</processEndTag>
    </configuration>
    ...
</plugin>

在我看来,使用===的代码行比默认的#%L代码行更好,后者看起来像是意外留下了垃圾:-)

对这些标记的唯一要求是唯一的,因此是_START_END部分。我还发现标签中的任何空格字符在插入到文件中之前都会被删除。

票数 9
EN

Stack Overflow用户

发布于 2014-06-21 01:58:23

The documentation for version 1.9 (latest at time of writing)表示,这些分隔符是用于查找报头的强制分隔符。

(1) #%L (2)项目说明(3) %% (4)版权所有(C) 2010贵组织(5) %% (6)许可证内容(7) #L%

对于用于检测标头开始的开始进程标记(从不抑制)。对于文件的delimiter

  • Copyright部分,请参阅下一节

  • 项目说明部分

  • 标头部分(请参见下一节

  • 用于检测标头结束的结束进程标记(从不抑制)。

<

  • G218

票数 7
EN

Stack Overflow用户

发布于 2020-08-19 20:35:16

取而代之的是使用Mycila license plugin,它是will do what you want (没有段标记),在某些方面更简单,并且在much more active development下。我也一直在使用这个插件,直到我遇到了this comment

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22549517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档