2

人们是否有一种标准方式强制在他们的 java/maven 构建中包含版权声明?我意识到这不是必需的,因为产品本身是抄写的,如果有人有我的来源,我会有更大的问题,但我被要求检查并想知道 checkstyle、PMD 或其他东西是否自动处理了这个.

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

4

3 回答 3

2

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

假设您想checkstyle.license用于您的版权声明。对于多模块构建,标准方法是创建一个专用模块来托管 Checkstyle 资源(请参阅多模块配置):

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

然后,在顶层包含 Checkstyle配置pom.xml

<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 规则,但这是另一回事)。调整它以满足您的需求。

于 2009-11-30T22:36:10.237 回答
2

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

于 2010-02-07T15:46:58.250 回答
0

如果您的项目位于 Git 存储库中,则可以遵循欧洲自由软件基金会的REUSE 标准。使用重用工具,您可以通过执行reuse lint. 对于持续集成 (CI),您可以使用fsfe/reuse Docker 映像。

于 2020-12-17T13:49:48.993 回答