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
Related
Project has structure:
enter image description here
my-project
|--base
|--src
|--target
|--pom
|--uiFramework
|--src
|--target
|--pom
|--apiFramework
|--src
|--target
|--pom
|--uiJourneyTemplate
|--src
|--target
|--pom
|--pom
|--sonar-project.properties
where POM file has:
<modules>
<module>base</module>
<module>uiFramework</module>
<module>uiJourneyTemplate</module>
<module>apiFramework</module>
</modules>
Each module in POM file has parent section.
in the main folder sonar-properties file has:
sonar.sourceEncoding=UTF-8
sonar.projectKey=com.java.framework:FRAMEWORK
sonar.sources=src
sonar.java.binaries=**/*
sonar.exclusions=**/*.js, uiJourneyTemplate/**/*
#sonar.java.libraries=**/*.jar
#List of module identifiers
sonar.modules=base,uiFramework,apiFramework
#base settings
base.sonar.projectName=com.java.framework:base
module1.sonar.sources=src/main/java
#uiFramework settings
uiFramework.sonar.projectName=com.java.framework:uiFramework
uiFramework.sonar.sources=src/main/java
#apiFramework settings
apiFramework.sonar.projectName=com.java.framework:apiFramework
apiFramework.sonar.sources=src/main/java
I tries different variations.
In the result I see that in sonar I have only one java file form base module and POM files from each modules:
in the console for others java file I have:
ERROR: Unable to create symbol table for : 'uiFramework/src/main/java/utils/waitings/SmartWait.java'
java.lang.IllegalArgumentException: Unsupported class file major version 61
the same for ALL others classes
what can u recommend?
thanks
SOLVED:
problem is: NOT possible to use JAVA 17 with SOnarQube 7.9.1 for now - need to use JAVA 11 and will work fine!
https://community.sonarsource.com/t/sonarqube-only-pom-files-push-to-sonar-for-multi-modules-project/57369/4
I am new to Sonar.
I have multi-module maven project.
please find the Project structure below
-Parent
| -Module A
|
-pom.xml (Module A)
| -Module B
|
-pom.xml (Module B)
| -Module C
| |
| -pom.xml (Module C)
|
--pom.xml (parent pom)
Note : (Module C is shared module in Module A/ Module B - means Internally module C will the part of into Module A , Module B library)
Based on the Project requirement we have these structure.
Module A - works for external users.
Module B - works for internalusers.
Module C -common b/w both the module.
I am trying to create single sonar report for both the module, but I am not able to integrate all the module junit report (Module A and Module B report)
into single report.I followed couple of example to combine the muti-module maven porject but nothing works.
similar issue1 similar issue2
github-example (reference given in sonar)
I had similiar problem with over 40 modules which were even nested. What you have to do is to create whole sonar configuration in parent pom.
<sonar.host.url>set url here (default is localhost)</sonar.host.url>
<sonar.login>user for host url (default admin)</sonar.login>
<sonar.password>password for host url (default is admin)</sonar.password>
<sonar.projectName>optional name for whole project in sonar view</sonar.projectName>
<sonar.projectDescription>optional project description for sonar view</sonar.projectDescription>
<sonar.projectBaseDir>like name says you can set project base dir, if you have parent pom as a separate module then you can type ".." to set main directory with all modules</sonar.projectBaseDir>
Set properly all modules which will be analysed separately for the whole project:
<sonar.modules>module1, module2, module3</sonar.modules>
Configure each one of them properly:
<module1.sonar.projectName>module1</module1.sonar.projectName>
<module1.sonar.projectBaseDir>module1/</module1.sonar.projectBaseDir>
<module1.sonar.sources>optionally set sources to proper directory for example src/main/java</module1.sonar.sources>
<!-- similiar for other 2 projects -->
That way all junit reports will be used per module but it will be listed in single project with modules. That way you will be able to see reports per module and per whole single project.
It's a good practise to check results after adding every single module. In case of failure simply check error in console and fix the problem.
I am able to achieve Integration test coverage using sonar with Jococo plugin.
To run the Sonar in local, i was facing the issue with SCM error in sonar.
Every time it was failing in the in sonar report creation.
For resolving the issue in local you need to disable the SCM configuration in sonar.
login in local sonar as Admin - admin/admin (default username/password)
Now under setting we have SCM tab - disable the SCM Senor and save the SCM Setting.
Now in Dashboard --> Configure widgets .Search "Integration Tests Coverage"
Now add widget into your Project Dashboard.
Follow the same configuration in your pom.xml as given in the link.
https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco
In a multi-project build I have a module that in itself is composed of two sub-projects. If I just want the option of building the top-level module but also ensure both the sub-projects within it are also built, how I do achieve this?
include 'moduleA', 'moduleB', 'moduleC' (root project settings.gradle)
project(':moduleC').projectDir = new File('path to custom module that includes sub-projects)
project(':moduleC').settingsDir = ?? (gradle fails because there is no settingsDir path)
but moduleC has a settings.gradle in itself that has
include 'api'
include 'server'
Now I want both these to be triggered when I specify gradlew :moduleC:build, but instead it just builds moduleC root project. Is there a way? This use case does seem valid to me (i.e. for modularity, you want to keep the inclusion of sub-projects at moduleC's level and not at root level).
Thanks,
Paddy
As of Gradle 2.2, only a single settings.gradle per build is supported. If that file contains include "moduleC:api" and include "moduleC:server", then running gradle build from moduleC's project directory will also build api and server.
I'm struggling with sonar server and sonar runner (standalone via commandline). My project sonar file is:
# Required metadata
sonar.projectKey=org.codehaus.sonar:calculator
sonar.projectName=Calculator
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Language
sonar.language=py
# Encoding of the source files
sonar.sourceEncoding=UTF-8
And my command is
/opt/sonar-runner/bin/sonar-runner -Dsonar.projectBaseDir=/var/lib/jenkins/workspace/Servidor-RDS/serv/rdsweb/WebContent/fccma/js/fcc/tests/python-sonar-runner/ -Dproject.settings=/var/lib/jenkins/workspace/Servidor-RDS/serv/rdsweb/WebContent/fccma/js/fcc/tests/python-sonar-runner/sonar-project.properties
Nothing exotic. I haven't any project in sonar (I've delete all), and my project structure is
src/
myCaluclator/
calculator.py
init.py
Calculator code is:
class Calculator(object):
def add(self, x, y):
return x + y
I always get an:
Caused by: org.sonar.api.resources.DuplicatedSourceException: Duplicate source for resource: org.sonar.api.resources.File#7d3e8935[key=myCalculator/calculator.py,dir=myCalculator,filename=calculator.py,language=Python]
at org.sonar.batch.index.SourcePersister.saveSource(SourcePersister.java:45)
at org.sonar.batch.index.DefaultPersistenceManager.setSource(DefaultPersistenceManager.java:78)
at org.sonar.batch.index.DefaultIndex.setSource(DefaultIndex.java:456)
at org.sonar.batch.DefaultSensorContext.saveSource(DefaultSensorContext.java:161)
at org.sonar.api.batch.AbstractSourceImporter.parseDirs(AbstractSourceImporter.java:88)
Do I need to clean some cache or something?
Thanks in advance.
I found the solution:
The sonar.sources is present in my sonar-runner properties and in my project properties, so all files are declared twice.
My error
I am using Maven 3.0.3 and I have a multiple module maven project which I want to use for Archetype creation. Struture is like:
Main_Project
----pom.xml
----Module_1
----pom.xml
----src
----main
----java
----com
----mycompany
----domain
----DomainT.java
----repo
----resources
----webapp
----test
----Module_2
----pom.xml
----src
----main
----java
----com
----mycompany
----web
----WebT.java
----resources
----webapp
----test
Now, when I use the following cmd in the Module_2, archetype is created successfully and correctly i.e.
c:\Main_Project\Module_2>mvn archetype:create-from-project
But, when I run the same command from the main folder (i.e. c:\Main_Project), the package structure is not created (for 'generate' cmd) and still the original package structure exists in the both the modules. What I mean is the package name in java and other files gets replaced with correct variables but the package folder structure is no created .e.g.
The original structure was:
----src
----main
----java
----com
----mycompany
----domain
----DomainT.java
After I run the cmd, mvn archetype:generate -DarchetypeCatalog=local
Define value for property 'groupId': : com.sample
Define value for property 'artifactId': : test_project
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': com.sample: :
Still the folder structure when generated inside the Module_1\src\main\java folder is same as above (i.e. Module_1\src\main\java\com\mycompany) and not like Module_1\src\main\java\com\sample
Not sure what I can do to make it work?
Fixed now.
In parent pom.xml, the module declaration was inside profiles.