问题
All of my SonarQube code analysis Java projects are failing on this rule.
Each source file should start with a header stating file ownership and the license which must be used to distribute the application. This rule must be fed with the header text that is expected at the beginning of every file.
There is one parameter:
headerFormat Expected copyright and license header (plain text)
But there are no examples of how this should be configured. By default headerFormat is empty and I cannot find documentation on configuring this rule.
I'm guessing there should be some kind of regular expression or template language that can be used?
回答1:
squid:S1451 "Copyright and license headers should be defined" has two parameters:
- headerFormat
- isRegularExpression
In headerFormat you define expected text. If you set isRegularExpression to true, then the text will be treated as regular expression.
If you use normal text, then you need to put full license, e.g.:
/*
* Maven Plugin Utils
* http://www.gabrys.biz/projects/maven-plugin-utils/
*
* Copyright (c) 2015 Adam Gabryś
*
* This file is licensed under the BSD 3-Clause (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* https://raw.githubusercontent.com/gabrysbiz/maven-plugin-utils/master/src/main/resources/license.txt
*/
If you use regular expression, then you can omit some parts, e.g.:
^\/\*.+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:.+$
回答2:
only change the default text for "headerFormat" on SonarQube server:
来源:https://stackoverflow.com/questions/31462870/sonarqube-rules-squids1451-copyright-and-license-headers-should-be-defined