首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有许可插件的Maven多模块项目

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

Stack Overflow用户
提问于 2013-01-14 02:08:06
回答 3查看 11.3K关注 0票数 2

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

代码语言:javascript
复制
─── transfuse-project
    ├── examples
    │   ├── helloAndroid
    │   │   ├── pom.xml
    │   │   ├── ...
    │   ├── integrationTest
    │   │   ├── pom.xml
    │   │   ├── ...
    │   ├── pom.xml
    │   └── ...
    ├── transfuse
    │   ├── pom.xml
    │   ├── ...
    ├── transfuse-api
    │   ├── pom.xml
    │   ├── ...
    ├── NOTICE
    └── pom.xml

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

代码语言:javascript
复制
        <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在项目根目录中找不到我提供的通知文件:

代码语言:javascript
复制
[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]

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

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-01-14 02:29:05

尝试使用以下命令使用绝对路径

代码语言:javascript
复制
<header>${basedir}/NOTICE</header>

如果这不起作用,尝试set a property to and in the parent module's basedir并使用它:

代码语言:javascript
复制
<header>${main.basedir}/NOTICE</header>

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

代码语言:javascript
复制
mvn clean install -Dmain.basedir=path/to/main/basedir

编辑:

好的,一个完整的选择是在你的许可证插件之前执行maven-dependency-plugin。但您必须确保家长附加通知(使用maven-assembly-plugin plugin)

代码语言:javascript
复制
<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会在以下位置更改:

代码语言:javascript
复制
<header>${project.build.directory}/license/NOTICE</header>

Edit2:

我偶然发现了find-maven-plugin。我认为这是可行的:

代码语言:javascript
复制
<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>
票数 2
EN

Stack Overflow用户

发布于 2013-07-12 18:40:12

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

代码语言:javascript
复制
<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的文件。

票数 1
EN

Stack Overflow用户

发布于 2015-01-16 04:01:39

在设置了以下两个配置属性的情况下尝试您的示例:

代码语言:javascript
复制
<plugin>
  <groupId>com.mycila</groupId>
  <artifactId>license-maven-plugin</artifactId>
  <version>2.7</version>
  <configuration>
    <header>/NOTICE</header>
    <aggregate>true</aggregate>
  </configuration>
</plugin>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14306500

复制
相关文章

相似问题

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