maven-license-plugin:为所有孩子使用parentPom许可证

时间:2014-04-24 16:23:16

标签: java maven

我正在尝试使用maven-license-plugin获取多模块项目的许可证和标头信息。我想避免使用许可证的多个副本,并保持pom文件尽可能易于维护。为此,我将插件信息放入元素中的parentPom中。我完全配置了插件并将必要的文件放入父项目中。所以,在父母那里,我有:

<pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>1.6</version>
                    <configuration>
                        <licenseName>my_license</licenseName>
                        <licenseResolver>${project.baseUri}/src/license</licenseResolver>
                    </configuration>
                    <executions>
                        <execution>
                            <id>first</id>
                            <goals>
                                <goal>update-file-header</goal>
                            </goals>
                            <phase>process-sources</phase>
                        </execution>
                    </executions>
                </plugin>
</pluginManagement>

然后我将这个插件的引用放入其中一个子pom文件中:

<plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>license-maven-plugin</artifactId>
            </plugin>
</plugins>

孩子无法构建,因为它试图沿着孩子的项目路径找到licenses.properties文件,而不是父项。如何让孩子们在父项目中查找licenses.properties?

1 个答案:

答案 0 :(得分:2)

解决方法是使用如下所述的classpath选项:

http://mojo.codehaus.org/license-maven-plugin/examples/example-add-license.html

  

使用类路径中的许可证解析器从版本1.3开始,它就是   可以使用类路径中的许可证解析器(包含在   jar或插件依赖项的任何依赖项。)

     

只需在插件配置中使用classpath://协议。

     

想象一下,您在工件中拥有许可证解析程序   com.my:extraLicenseResolvers:1.0 in package foo.bar

     

下一个示例显示如何在类路径中使用此许可证解析程序:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>license-maven-plugin</artifactId>
  <version>1.6</version>
  <configuration>
      <licenseName>my_license</licenseName>
      <licenseResolver>classpath://foo/bar</licenseResolver>
  </configuration>
  <executions>
      <execution>
          <goals>
              <goal>update-file-header</goal>
          </goals>
          <phase>process-sources</phase>
      </execution>
  </executions>
  <dependencies>
      <dependency>
          <groupId>com.my</groupId>
          <artifactId>extraLicenseResolvers</artifactId>
          <version>1.0</version>
      </dependency>
  </dependencies>
</plugin>

对此不明显的是,您确实需要一个包含许可证文件的独立包。似乎没有办法将这些信息保存在父pom项目中。

最后,这个解决方案有效,我们能够为我们的许可证信息提供一个位置,以便所有儿童pom文件都使用。