How remove CSS, HTML rules in Java project?

SonarQube 9.1

I use sonar for Java project. I need rules only for java code. But SonarQube has built-in rules CSS and HTML. And use it for my java project.


Is it possible to turn off CSS and HTML rules?
I need only Java rules for my java project.

Here Quilty profile:

And this html profile. As you can see I can’t remove it.

Hi,

use the sonar.exclusions property for this project like that
sonar.exclusions=**/*.css,**/*.html

see Analysis Parameters | SonarQube Docs

Note that only parameters set through the UI are stored in the database. For example, if you override the sonar.exclusions parameter via command line for a specific project, it will not be stored in the database. Subsequent analyses, or analyses in SonarLint with connected mode, would still be executed with the exclusions defined in the UI and therefore stored in the DB.

and
https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/

Gilbert

1 Like

Project Settings-> General Settings -> Analysis Scope -> Coverage Exclusions

*/.css, */.html

But it not help. Same result.

You’ve used the wrong property.
Has to be sonar.exclusions not sonar.coverage.exclusions

Not help. Same result

A change of the project settings only takes effect with the next analyis.
Have you already run a new analysis ?

Yes, I start next Sonar analysis… but it not help. Same result.

Did you check if your settings were part of the game ?
Check either via console log of Sonarqube analysis, should have something like:

INFO: Project configuration:
INFO:   Excluded sources: src/archive/**/*, **/node_modules/**, gen/**/*.java, **/*.html, **/*.css

As you see, we’re also excluding all html and css files for specific Java projects and it works as expected.

or via background tasks / scanner context
https://yoursonarhost/admin/background_tasks see scanner context under the gearwheel
for a specific analysis.

open_scanner_context

https://yoursonarhost/admin/background_tasks

Show Scanner Context

Scanner Context: MyProject [Project Analysis]

Project server settings:
  - sonar.coverage.exclusions=**/generated-sources/**,**/src/test/**,./.svn,**/*Header.java,**/target/**/*.*
  - sonar.exclusions=**/*.css,**/*.html,**/target/**/*.*

As you can see the settings are correct. But it not help.

P.S
In folder %SONAR_HOME%/logs has the next logs:

access.log
ce.log
es.log
sonar.20211129.log
web.log

But in this logs I’m not found sml like this:

INFO: Project configuration:
INFO:   Excluded sources: src/archive/**/*, **/node_modules/**, gen/**/*.java, **/*.html, **/*.css

You need to check the Sonarqube analysis logs (typically running on Jenkins or similar),
not the Sonarqube server logs (access.log, ce.log …).

Yes, you was right.
I use Jenkin’s job to run sonar scanner.

Steps to fix:

  1. Change in Jenkins’s job this settings:

sonar.exclusions=**/*.css,**/*.html,**/target/**/*.*

  1. Run Jenkin’s job

And now success exclude all css and html files in Sonar report.

Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.