2

我有一个多模块项目,我正在尝试设置许可证插件来管理所有许可证。这是项目设置:

─── transfuse-project
    ├── examples
    │   ├── helloAndroid
    │   │   ├── pom.xml
    │   │   ├── ...
    │   ├── integrationTest
    │   │   ├── pom.xml
    │   │   ├── ...
    │   ├── pom.xml
    │   └── ...
    ├── transfuse
    │   ├── pom.xml
    │   ├── ...
    ├── transfuse-api
    │   ├── pom.xml
    │   ├── ...
    ├── NOTICE
    └── pom.xml

每个 pom.xml 都继承自 transfuse-project pom.xml。在项目 pom.xml 中,我设置了许可证插件以将 NOTICE 应用于相关文件:

        <plugin>
            <groupId>com.mycila.maven-license-plugin</groupId>
            <artifactId>maven-license-plugin</artifactId>
            <version>1.9.0</version>
            <configuration>
                <header>NOTICE</header>
                <includes>
                    <include>**/*.java</include>
                    <include>**/*.xml</include>
                </includes>
                <excludes>
                    <exclude>**/.*/**</exclude>
                    <exclude>target/**</exclude>
                    <exclude>**/AndroidManifest.xml</exclude>
                </excludes>
                <properties>
                    <year>2013</year>
                    <name>John Ericksen</name>
                </properties>
                <useDefaultExcludes>true</useDefaultExcludes>
                <strictCheck>true</strictCheck>
            </configuration>
            <executions>
                <execution>
                    <id>check-headers</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

如果我直接从根 (transfuse-project) 构建,则此配置有效。当我直接构建 integrationTest 示例或 api 时出现问题。Maven 找不到我在项目根目录中提供的 NOTICE 文件:

[ERROR] Failed to execute goal com.mycila.maven-license-plugin:maven-license-plugin:1.9.0:check (check-headers) on project transfuse-api: Some files do not have the expected license header -> [Help 1]

更糟糕的是,它找到了另一个依赖项的 NOTICE 文件。如果我mvn license:format在子模块中运行,它将用依赖项的 NOTICE 文件替换所有模块的头文件。

我相信我可以在每个子模块中添加一个 NOTICE 文件来解决这个问题,并为每个子模块 pom 配置它自己的许可证插件,但如果可能的话,我想避免这种重复。是否有一些配置或设置适用于我的项目设置?

4

3 回答 3

2

尝试使用绝对路径

<header>${basedir}/NOTICE</header>

如果这不起作用,请尝试在父模块的 basedir 中设置属性并使用它:

<header>${main.basedir}/NOTICE</header>

第三种选择是在运行时设置属性:

mvn clean install -Dmain.basedir=path/to/main/basedir

编辑:

好的,另一个选择是在您的许可证插件之前执行maven-dependency- plugin。但是您必须确保父级附上通知(使用maven-assembly-plugin plugin

<plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>2.6</version>
         <executions>
           <execution>
             <id>unpack-parent</id>
             <phase>verify</phase>
             <goals>
               <goal>unpack</goal>
             </goals>
             <configuration>
               <artifactItems>
                 <artifactItem>
                   <groupId>parent</groupId>
                   <artifactId>parent</artifactId>
                   <version>parent</version>
                   <type>pom</type>
                   <overWrite>false</overWrite>
                   <outputDirectory>${project.build.directory}/license</outputDirectory>
                   <includes>NOTICE</includes>
                 </artifactItem>
               </artifactItems>
             </configuration>
           </execution>
         </executions>
       </plugin>

然后发生的header变化:

<header>${project.build.directory}/license/NOTICE</header>

编辑2:

我遇到了 find-maven-plugin。我认为这可以工作:

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>find-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>find-notice-file</id>
            <goals>
                <goal>find</goal>
            </goals>
            <phase>validate</phase>
            <configuration>
                <propertyName>notice.file</propertyName>
                <file>NOTICE</file>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2013-01-13T18:29:05.427 回答
1

实际上有一种更简单的方法可以做到这一点。只需在配置中设置aggregate标签即可true。这是完整的maven-license-plugin定义:

<plugin>
    <groupId>com.mycila.maven-license-plugin</groupId>
    <artifactId>maven-license-plugin</artifactId>
    <version>1.10.b1</version>
    <configuration>
        <header>etc/header.txt</header>
        <aggregate>true</aggregate>
        <includes>
            <include>**/*.java</include>
        </includes>
    </configuration>
</plugin>

然后,您只需要在父根目录中调用一个header.txt文件etc/header.txt

于 2013-07-12T10:40:11.870 回答
0

使用这两个配置属性集尝试您的示例:

<plugin>
  <groupId>com.mycila</groupId>
  <artifactId>license-maven-plugin</artifactId>
  <version>2.7</version>
  <configuration>
    <header>/NOTICE</header>
    <aggregate>true</aggregate>
  </configuration>
</plugin>
于 2015-01-15T20:01:39.437 回答