Sonar, how to exclude binaries - sonarqube

I am importing my full binaries folder which contains binaries of classes I don't want to analyze, as well as tests that I also want to analyze. Despite Sonar documentation stating that the sonar.properties property supports comma separated values, it is incorrect. If I try to include many folders, separating with a comma, only the first folder path will be included in the analysis.
I know in the Sonar dashboard you can exclude source files, but it does not say anything about excluding .class files.

I know in the Sonar dashboard you can exclude source files, but it does not say anything about excluding .class files.
Following "SONAR - How to exclude packages that is defined under “sonar.test”", a directive like:
/path/to/class/dir/**/*.class
should exclude all .class files.
It should be fairly similr to the sonar.exclusions Analysis Parameter.

Related

In a Windows 10 UWP WinJS App, how can I decide which files get included in the build?

I'm building a UWP app with javascript and in a subfolder, I have a node_modules folder and a bunch of files that are there for compilation and debugging, but should not be in the final build.
I don't know how to include or exclude folders from the build, but it's important that I am able to keep them visible in the project.
I don't know how to include or exclude folders from the build.
When you build a project that contains several files, you can list each file separately in the project file, or you can use wildcards to include all the files in one directory or a nested set of directories. And you can explicitly exclude that file or directory from the list of inputs. There may also be a file in a project that you only want to include under certain conditions. You can explicitly declare the conditions under which a file is included in a build. For more detail you could refer MSBuild Items official document.
I have a node_modules folder and a bunch of files that are there for compilation and debugging, but should not be in the final build.
Please refer the following screenshot, if you have set file Package Action as Content the file will be selected to build. You could check if the value is correct.

Excluding files from Sonarqube

I'm trying not to analyse test files with Sonarqube.
I have several Maven subprojects and the test files are under these paths:
subproject1/src/test/, subproject2/src/test/ and so on
I'm passing the following option from Maven:
-Dsonar.exclusion=src/test/**
However, the test files are still analysed.
I also tried:
-Dsonar.exclusions=**/src/test/**,**/test/*,subproject1/src/test/**,**/*Spec.scala
But issues are still raised on test code.
There is no property by the name sonar.exclusion. sonar.exclusions is a valid property, but it applies to source files. You're trying to exclude test files - and yes the scanners do make the distinction, especially for Maven projects.
You should use instead sonar.test.exclusions
If you want to omit only certain rules, you have two options:
remove the rule from your profile
use Administration > Analysis Scope > Ignore Issues on Multiple Criteria to turn the rule off for only a subset of files.

SonarQube excluding files, directories, and generated code?

The code base I am working with has a lot of generated code. In addition, there are also some deprecated files that I would want to exclude from SonarQube analysis. I've read up the documentation and looked at some answers on here about that, but it does not help in my case.
I have a multi-module maven project. So I have multiple projects in my workspace that are all part of a large application. Say I want to exclude this file:
/home/username/workspace/com.mst.rtra.importing.message/bin/com/mst/rtra/importing/message/idl/parse/idlparser.java
I don't really know how to write this in the exclusions settings on SonarQube because of how long the filepath is. Also, what if I want to exclude another file, but from a different module, say :
/home/username/workspace/com.mst.rtra.interpreter.create/
I am confused about I should write this in the exclusions box in project settings. Should I write the absolute file path due to the multi-module nature of this project? Or is there some other convention used?
In addition, if I want to exclude generated files from analysis, I would need to put file:/generated-sources/ as I saw in another answer. However, after analysis, I can still view the analysis results of those files when I open up the project in SonarQube dashboard.
We use ant rather than maven, and an older version of the Sonar ant task at that. But what works for us is setting a sonar.exclusions property in our build.xml, which accepts wildcards for filenames. For example:
<property name="sonar.exclusions" value="**/com/ex/wsdl/asvc/*.java,**/com/ex/wsdl/bsvc/*.java"/>
That skips analyzing all the code generated from a wsdl file for two services. You ought to be able to do something similar for maven.

How to remove sources in maven

I'm using https://jax-ws-commons.java.net/jaxws-maven-plugin/ to generate sources from wsdl files. I'm doing multiple executions(for different wsdls) with different sourceDestDir. This is working as expected and it is generating sources in different directories.
But the plugin is also adding all of these sourceDestDir's to build sources and the maven-compiler-plugin tries to compile them automatically.
I want to prevent this from happening. i.e I want to remove the source directories added by jaxws-maven-plugin so that I can define what should be compiled and what shouldn't be. Is this possible?

Where in the Maven Standard Directory Layout should generated resources go?

I'd like to generate some resources (JavaHelp search index in this case), but I can't seen to see where those generate files should go to get into the jar. I put them in target/generated-sources, but they are ignored. Should it be target/classes?
/generated-sources directory is used by various tools generating sources (duh!), like xjc or wsdl2java. This directory is later included in the compilation phase.
/target/classes is everything that should be included in the final JAR, which answers your question. Also the contents of /src/main/resources is included, but this directory is typically part of version control and is not meant for generated artifacts.
It turns out that generated-source directories are not automatically included in the jar. However, Intellj assumes there are and treats them as such, hence my confusion.
You need to use the Maven build helper plugin to fix this issue, for example:
https://github.com/alexec/javahelp-skeleton/blob/master/pom.xml

Resources