java - 如何使用 license-maven-plugin

标签 java maven

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

所以我有以下 pom.xml:

<?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>

我正在从命令行调用以下内容:

mvn license:update-file-header

这一切都通过了,但我的许可证 header 最终看起来像这样:

/*
 * #%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%
 */

显然,我不想在我的许可证 header 中使用 #%L%%#L%。我需要设置什么才能摆脱这些?

最佳答案

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

在我的项目中,我将它们改成了更漂亮的东西:

<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 部分。我还发现标签中的所有空格字符在插入文件之前都被删除了。

关于java - 如何使用 license-maven-plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22549517/

相关文章:

java - 如何在创建文件的过程中显示进度条?

java - 如何确定 Maven 依赖项的 MySQL/MariaDB 版本?

maven - 构建时在哪个生命周期点会忽略测试?

java - jenkins与maven集成问题

java - 为什么 Google Eclipse 插件 GWT 编译器无法识别 Ivy 依赖项类路径?

java - 使用自定义构造函数设置 BaseActivity 以从子类提供数据

java - 在多个 Activity 中使用 AsyncTask

java - Jasper 报告 PDF 印地文版

java - JAXB - 检查是否存在子元素

maven-2 - 如何获取 Maven 本地仓库位置?