繁体   English   中英

带有许可插件的Maven多模块项目

[英]Maven multi-module project with license plugin

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

─── 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,但我想尽可能避免重复。 是否有一些配置或设置可用于我的项目设置?

尝试使用绝对路径

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

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

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

第三个选项是在运行时设置属性:

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

编辑:

好的,另一个选择是在许可插件之前执行maven-dependency- plugin。 但你必须确保父级附加NOTICE(使用maven-assembly-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>

EDIT2:

我遇到了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>

实际上有一种更简单的方法。 只需在配置中将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>

然后,您只需要在父根目录中的etc/header.txt中有一个名为header.txt的文件。

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

<plugin>
  <groupId>com.mycila</groupId>
  <artifactId>license-maven-plugin</artifactId>
  <version>2.7</version>
  <configuration>
    <header>/NOTICE</header>
    <aggregate>true</aggregate>
  </configuration>
</plugin>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM