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

发布于 2024-08-13 04:17:32 字数 160 浏览 6 评论 0原文

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

有没有一个工具可以处理版权检查?

Is there a standard way people enforce the inclusion of copyright notices in their java/maven builds? I realize that it shouldn't be necessary since the product itself is copy-written and if someone has my source I have much bigger problems, but I'm being asked to check and was wondering if checkstyle, PMD or something else handled this automatically.

Is there a tool which handles checking for copyright?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜味拾荒者 2024-08-20 04:17:32

,Checkstyle(以及 maven-checkstyle-plugin< /a>) 可以做到这一点,它可以检查每个源文件是否包含许可证头。将该标头放入文本文件中并使用 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

然后,包含 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 规则,但这是另一个故事)。对其进行调整以满足您的需求。

Yes, Checkstyle (and the maven-checkstyle-plugin) can do that, it can check that every source files do contain a license header. Put that header in a text file and use the headerLocation to point on it (it uses by default LICENSE.txt).

Let's say you want to use checkstyle.license for your copyright notices. For a multi-modules build, the standard approach is to create a dedicated module to host Checkstyle resources (see Multimodule configuration):

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

Then, include the Checkstyle configuration in the top level 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>

This setup will ensure that a copyright header is present in source files (and apply other Checkstyle rules but this is another story). Adapt it to suit your needs.

肩上的翅膀 2024-08-20 04:17:32

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

If your project is in a Git repository, you can follow the REUSE standard from the Free Software Foundation Europe. With the reuse-tool you can check REUSE compliance by executing reuse lint. For continuous integration (CI) you can use the fsfe/reuse Docker image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文