I am making an attempt to create separate dashboards with a folder and a sub-folder of the same project. My configuration file looks like this
sonar:
projectKey: myproject
projectName: my project name
projectVersion: "1.0"
sourceEncoding: UTF-8
dynamicAnalysis: reuseReports
exclusions: &global.exclusions
...
test:
inclusions:
...
exclusions: &global.test.exclusions
...
# exclude files which are usually untested
coverage.exclusions:
...
# exclude files which commonly have repeated blocks
cpd.exclusions: []
# report paths are injected from the code
javascript.lcov.reportPaths: &reportPaths []
typescript.lcov.reportPaths: *reportPaths
issue.ignore.multicriteria:
...
modules:
- frontend
- cms
# modules
frontend.sonar:
projectName: frontend
projectBaseDir: .
sources: &frontend.sources
- frontend
tests:
- *frontend.sources
- frontend/testutils
exclusions: &frontend.exclusions
- 'frontend/cms'
- 'frontend/cms/**'
- 'frontend/cms-store'
- 'frontend/cms-store/**'
- *global.exclusions
cms.sonar:
projectName: cms
projectBaseDir: .
sources: &cms.sources
- 'frontend/cms'
- 'frontend/cms-store'
tests:
- *cms.sources
exclusions:
- *global.exclusions
The problem is that I am getting the error of
ERROR: File ... be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
I tried to change inclusions and exclusions accordingly, but it doesn't look to work.
Any suggestions?
Related
So I have a bunch of icons in a folder structure under project resources
- src/main/resources/META-INF/resources/
- icons/
- icon-set-alpha/
- a1.svg
- a2.svg
- ...
- icon-set-beta/
- b1.svg
- b2.svg
- ...
- ...
I now want to write a task, that when copying those resources takes whatever's there and bundles it (not zip) and only copies the bundled versions into the build directory.
I.e.the build result should look like
- build/resources/main/META-INF/resources/
-icons/
- icon-set-alpha.svg
- icon-set-beta.svg
I can of course write a task that after copying the folders to the build directory goes through all the folders and creates bundled versions there and deletes the folders.
Is there a way to do it on-the-fly, though?
We have projects with a structure like this ( a root pom and 2 sub modules ) :
local-module
implementation-module
pom.xml
By default sonar seems to use these sources :
<sonar.sources>pom.xml,src/main,src/test</sonar.sources>
We want to analyse YML files or other files in others locations.
But after trying various configuration according to https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
This one :
<sonar.sources>.</sonar.sources>
<sonar.tests>src/test/java</sonar.tests>
<sonar.test.inclusions>src/test/java</sonar.test.inclusions>
<sonar.exclusions>src/test/java</sonar.exclusions>
produces the following error :
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project sample: null: MojoExecutionException: NullPointerException
and this one :
<sonar.sources>.</sonar.sources>
<sonar.test.exclusions>src/test/java</sonar.test.exclusions>
produces :
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project pew-fwk-sample: File sample-impl/src/test/java/com/xxx/sample/FeaturesTest.java can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]
Do you have any ideas on the solutions ?
I would not change to many parameters at once. Some of these properties are provided by the maven plugin and should not need to be changed. I would start just using the exclusions parameter. Note that it uses some ant style pattern to exclude files. If you don't provide it it will only apply to that specific file or folder. The page you linked contains some example at the bottom:
# Exclude all classes ending by "Bean"
# Matches org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java, etc.
sonar.exclusions=**/*Bean.java,**/*DTO.java
# Exclude all classes in the "src/main/java/org/sonar" directory
# Matches src/main/java/org/sonar/MyClass.java, src/main/java/org/sonar/MyOtherClass.java
# But does not match src/main/java/org/sonar/util/MyClassUtil.java
sonar.exclusions=src/main/java/org/sonar/*
# Exclude all COBOL programs in the "bank" directory and its sub-directories
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl, bank/data/REM012345.cob
sonar.exclusions=bank/**/*
# Exclude all COBOL programs in the "bank" directory and its sub-directories whose extension is .cbl
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl
sonar.exclusions=bank/**/*.cbl
So something like <sonar.exclusions>src/main/java/**/*</sonar.exclusions> should exclude all sources. Above is an example to only exclude Dto classes. Usually the exclusions are enough to narrow the focus down. But includes work the same way should you want to go that way.
I have the next problem. I'm developing a project in java and create sonar.properties file to use SonarQube (v6.7.2). My project have two modules. The project structur is:
my-project
|--core-utils
|--src
|--target
|--pdf-utils
|--src
|--target
And sonar.properties is:
First module
sonar.moduleKey=com.app.core.pdf:pdf-utils
sonar.projectBaseDir=/var/lib/jenkins/workspace/MyProject/pdf-utils
sonar.projectKey=com.app.core.pdf:pdf-utils
sonar.projectName=pdf-utils
sonar.projectVersion=0.90.0-SNAPSHOT
sonar.sources=/var/lib/jenkins/workspace/MyProject/pdf-utils/src/main/java
sonar.working.directory=/var/lib/jenkins/workspace/MyProject/pdf-utils/target/sonar
sonar.java.binaries=/var/lib/jenkins/workspace/MyProject/pdf-utils/target/classes
Second module
sonar.moduleKey=com.app.core:core-utils
sonar.projectBaseDir=/var/lib/jenkins/workspace/MyProject/core-utils
sonar.projectKey=com.app.core:core-utils
sonar.projectName=core-utils
sonar.projectVersion=0.90.0-SNAPSHOT
sonar.sources=/var/lib/jenkins/workspace/MyProject/core-utils/src/main/java
sonar.working.directory=/var/lib/jenkins/workspace/MyProject/core-utils/target/sonar
sonar.java.binaries=/var/lib/jenkins/workspace/MyProject/core-utils/target/classes
Main module
sonar.host.url=http://localhost:9000/sonar
sonar.java.source=1.6
sonar.java.target=1.6
sonar.moduleKey=com.app.core:core-all
sonar.modules=com.app.core:core-utils,com.app.core.pdf:pdf-utils
sonar.projectBaseDir=/var/lib/jenkins/workspace/MyProject
sonar.projectKey=com.app.core:core-all
sonar.projectName=core-all
sonar.projectVersion=DEV-SNAPSHOT
sonar.sourceEncoding=UTF-8
Then runs SonarScanner and the result is:
The base directory of the module 'com.app.core:core-utils' does not exist: /var/lib/jenkins/workspace/MyProject/com.app.core:core-utils
I don't know why do this if I put base directory for each module.
Thanks!!
sonar.modules stores identifiers of the children modules. You have to use child identifier as prefix of all child's sonar properties. Example:
# Main module
sonar.host.url=http://localhost:9000/sonar
sonar.java.source=1.6
sonar.java.target=1.6
sonar.modules=coreutils,pdfutils
sonar.projectBaseDir=/var/lib/jenkins/workspace/MyProject
sonar.projectKey=com.app.core:core-all
sonar.projectName=core-all
sonar.projectVersion=DEV-SNAPSHOT
sonar.sourceEncoding=UTF-8
# First module
pdfutils.sonar.projectBaseDir=/var/lib/jenkins/workspace/MyProject/pdf-utils
pdfutils.sonar.projectKey=com.app.core.pdf:pdf-utils
pdfutils.sonar.projectName=pdf-utils
pdfutils.sonar.sources=/var/lib/jenkins/workspace/MyProject/pdf-utils/src/main/java
pdfutils.sonar.working.directory=/var/lib/jenkins/workspace/MyProject/pdf-utils/target/sonar
pdfutils.sonar.java.binaries=/var/lib/jenkins/workspace/MyProject/pdf-utils/target/classes
# Second module
coreutils.sonar.projectBaseDir=/var/lib/jenkins/workspace/MyProject/core-utils
coreutils.sonar.projectKey=com.app.core:core-utils
coreutils.sonar.projectName=core-utils
coreutils.sonar.sources=/var/lib/jenkins/workspace/MyProject/core-utils/src/main/java
coreutils.sonar.working.directory=/var/lib/jenkins/workspace/MyProject/core-utils/target/sonar
coreutils.sonar.java.binaries=/var/lib/jenkins/workspace/MyProject/core-utils/target/classes
I also cleanup your properties:
sonar.moduleKey - removed from all modules
sonar.projectVersion - removed from children modules
Referring to https://stackoverflow.com/a/18585688/3639934 I've put the following in my POM to exclude generated source files, which exist in target/generated-sources/x/y/z.
</properties>
<sonar.exclusions>file:**/generated-sources/**</sonar.exclusions>
</properties>
In my logfile I see no files excluded, however there are files in my project's directory under target/generated-sources/x/y/z.
[10:14:39.346] Source paths: pom.xml, src/main/java
[10:14:39.346] Test paths: src/test/java
[10:14:39.347] Binary dirs: target/classes
[10:14:39.348] Source encoding: UTF-8, default locale: de_DE
[10:14:39.348] Index files
[10:14:39.363] Excluded sources:
[10:14:39.363] file:**/generated-sources/**
[10:14:39.484] 47 files indexed
[10:14:39.487] 0 files ignored because of inclusion/exclusion patterns
I'm using SQ 5.1.1, Maven 3.2.3, Java 8.
Can anyone enlighten me please?
Ok, the log fooled me. The generated-sources are no part of the analysis right from the start, so it did not show up any excluded files.
When I change the exclusion pattern to match a file from say "src/main/java" it logs the expected exclusion (and does not analyze the file.)
I am having my directory structure as
src/
- main/
- java/
- com/
- resources/ // Folder where I have kept my properties file
- class1.java
- class2.java
When I am trying to build the JAR using maven the resources folder is getting skipped and I am having only this structure left
src/
- main/
- java/
- com/
- class1.class
- class2.class
I know that maven uses a conventional dir. structure for the resources as src/main/resources. But I want my resources folder to be at the same level where my class files are getting generated.
Can anyone please help me in this regard.
Thanks in advance.
The key is what you said - you want your resources to be at the same level where the class files are being generated. That doesn't mean they have to start in the same folder. They must simply have the same package structure. You may do this following the normal Maven file layout conventions as follows.
- src
- main
| - java
| - com
| - mycompany
| - Class1.java
| - Class2.java
| - resources
| - com
| - mycompany
| - someResources.properties
| - anotherResource.jpg
Note that the directory/package structure under /src/main/java and /src/main/resources is the same. When the maven-compiler-plugin and maven-resources-plugin have finished running, the result will be
- target
- classes
- com
- mycompany
- Class1.class
- Class2.class
- someResources.properties
- anotherResource.jpg
which is what you want.