如何确保java-maven构建的所有源文件都附带版权声明?

时间:2009-11-30 19:05:46

标签: maven-2 checkstyle copyright-display

人们是否有标准的方式在其java / maven版本中强制包含版权声明?我意识到它不应该是必要的,因为产品本身是复制写的,如果有人有我的来源我有更大的问题,但我被要求检查,并想知道checkstyle,PMD或其他什么自动处理

是否有处理版权检查的工具?

3 个答案:

答案 0 :(得分:2)

,Checkstyle(和maven-checkstyle-plugin)可以做到这一点,它可以检查每个源文件是否都包含许可证标头。将该标题放在文本文件中并使用headerLocation指向它(默认情况下使用LICENSE.txt)。

假设您想使用checkstyle.license作为版权声明。对于多模块构建,标准方法是创建一个专用模块来托管Checkstyle资源(参见Multimodule configuration):

whizbang
|-- pom.xml
|-- build-tools
|   |-- src
|   |   `-- main
|   |       `-- resources
|   |           `-- whizbang
|   |               |-- checkstyle.xml
|   |               `-- checkstyle.license
|   `-- pom.xml
|-- core
|-- gui
|-- jmx
`-- src

然后,在顶级pom.xml中加入Checkstyle configuration

<pluginManagement>
  <plugins>
    <!-- Apply checkstyle rules and fail the build in case of errors. The
         checkstyle config files are taken from the build-tools JAR module.-->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <!-- Lock down plugin version for build reproducibility -->
      <version>2.4</version>
      <dependencies>
        <dependency>
          <groupId>com.example.whizbang</groupId>
          <artifactId>build-tools</artifactId>
          <version>1.0</version>
        </dependency>
      </dependencies>
      <configuration>
        <consoleOutput>true</consoleOutput>
        <configLocation>whizbang/checkstyle.xml</configLocation>
        <headerLocation>whizbang/checkstyle.license</headerLocation>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
</pluginManagement>

此设置将确保源文件中存在版权标题(并应用其他Checkstyle规则,但这是另一个故事)。根据您的需求进行调整。

答案 1 :(得分:2)

我刚刚发现 http://code.google.com/p/maven-license-plugin/ 似乎也很合理

答案 2 :(得分:0)

如果您的项目位于Git存储库中,则可以遵循欧洲自由软件基金会的REUSE standard。使用reuse-tool,您可以通过执行-Identity来检查REUSE的合规性。对于持续集成(CI),您可以使用fsfe/reuse Docker映像。