我如何确保版权声明与Java Maven构建的所有源文件一起出现?

问题描述 投票:2回答:2

人们是否有一种标准的方法来强制在其Java / Maven版本中包含版权声明?我意识到这不是必须的,因为产品本身是抄写的,如果有人提供我的资源,我会遇到更大的问题,但是我被要求检查并想知道checkstyle,PMD或其他方法是否可以自动处理此问题。

是否有用于检查版权的工具?

java maven-2 checkstyle copyright-display
2个回答
2
投票

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

假设您要在版权声明中使用LICENSE.txt。对于多模块构建,标准方法是创建一个专用模块来承载Checkstyle资源(请参见checkstyle.license):

Multimodule configuration

然后,在顶层whizbang |-- pom.xml |-- build-tools | |-- src | | `-- main | | `-- resources | | `-- whizbang | | |-- checkstyle.xml | | `-- checkstyle.license | `-- pom.xml |-- core |-- gui |-- jmx `-- src 中包含Checkstyle configuration

pom.xml

此设置将确保在源文件中存在版权标头(并应用其他Checkstyle规则,但这是另一回事了)。对其进行调整以适合您的需求。


2
投票

我刚刚发现<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> 似乎也很合理

© www.soinside.com 2019 - 2024. All rights reserved.