如何使用license-maven-plugin

时间:2014-03-21 03:20:45

标签: java maven

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

所以我有以下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

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

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

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

3 个答案:

答案 0 :(得分:4)

The documentation for version 1.9 (latest at time of writing)表示这些是强制分隔符,可以找到标题。

(1) # % L
(2) Project description
(3) %%
(4) Copyright (C) 2010 your organization
(5) %%
(6) License content
(7) # L %
     
      
  1. 用于检测标头开头的开始过程标签(永远不要抑制它)。
  2.   
  3. 项目说明部分
  4.   
  5. 标题部分分隔符
  6.   
  7. 文件的版权部分(详见下一节)
  8.   
  9. 标题部分分隔符
  10.   
  11. 许可证部分
  12.   
  13. 用于检测标题结尾的结束过程标记(永远不要抑制它)。
  14.   

答案 1 :(得分:2)

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

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

SELECT
  kust_adr.KU_NAME AS "Customer Name",
  gas_daten.GAS_BEZ AS "Product Name",
  gas_przu.GAS_MIN_M2 AS "Price"
FROM kust_adr,
     gas_daten,
     gas_przu
WHERE gas_przu.GAS_KUNR = kust_adr.KU_NR
AND gas_daten.GAS_IDNR =
gas_przu.GAS_IDNR
AND (kust_adr.KU_ADR_ART = 0)

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

答案 2 :(得分:1)

使用Mycila license plugin代替will do what you want(无分段标记),在某种程度上更简单并且在much more active development下。我也用这个插件来敲打头,直到遇到this comment