繁体   English   中英

我如何确保版权声明伴随我所有的 java-maven 构建源文件?

[英]How do I ensure that copyright notices accompany all of my source files for a java-maven build?

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

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

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

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

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

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

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

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

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

暂无
暂无

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

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