SonarQube 规则鱿鱼:S1451 应定义版权和许可证标头

use*_*804 6 sonarqube sonarqube5.1

我的所有 SonarQube 代码分析 Java 项目都未能遵循此规则。

每个源文件都应以标头开头,说明文件所有权以及分发应用程序必须使用的许可证。此规则必须包含每个文件开头所需的标题文本。

有一个参数:

headerFormat 预期的版权和许可标头(纯文本)

但没有关于如何配置的示例。默认情况下 headerFormat 为空,我找不到有关配置此规则的文档。

我猜应该有某种可以使用的正则表达式或模板语言?

aga*_*rys 5

鱿鱼:S1451“应定义版权和许可证标头”有两个参数:

\n\n
    \n
  1. 标题格式
  2. \n
  3. 是正则表达式
  4. \n
\n\n

headerFormat中定义预期的文本。如果设置isRegularExpression设置为 true,则文本将被视为正则表达式。

\n\n

如果您使用普通文本,那么您需要输入完整的许可证,例如:

\n\n
/*\n * Maven Plugin Utils\n * http://www.gabrys.biz/projects/maven-plugin-utils/\n *\n * Copyright (c) 2015 Adam Gabry\xc5\x9b\n *\n * This file is licensed under the BSD 3-Clause (the "License").\n * You may not use this file except in compliance with the License.\n * You may obtain a copy of the License at:\n *\n *      https://raw.githubusercontent.com/gabrysbiz/maven-plugin-utils/master/src/main/resources/license.txt\n */\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果你使用正则表达式,那么你可以省略一些部分,例如:

\n\n
^\\/\\*.+www\\.gabrys\\.biz\\/projects\\/.+Copyright \\(c\\) [0-9]{4}.+This file is licensed under the.+\\(the "License"\\)\\..+You may not use this file except in compliance with the License\\..+You may obtain a copy of the License at:.+$\n
Run Code Online (Sandbox Code Playgroud)\n

  • 您应该将 Java 插件升级到 3.4(请参阅 http://jira.sonarsource.com/browse/SONARJAVA-656) (2认同)