SonarQube: Source is not present in module base directory - sonarqube

We have been executing sonar analysis successfully with SQ-4.5.4 version with no issues. Suddenly since couple days our sonar analysis build is failing with below error message:
It is not indexing any source file even though it has found them. We have made no changes in our pom.xml or project structure. I am not sure why it is adding "build/sonar" to base directory path that I have mentioned in pom.xml for project base directory. I tried giving relative path too but still issue is reproducible.
[INFO] [14:03:23.298] Base dir: /opt/customer/ci_workspace/sonar/10.1.0/TN/build/sonar
[INFO] [14:03:23.302] Source encoding: ISO-8859-1, default locale: en_US
[INFO] [14:03:23.304] Index files
[WARN] [14:03:24.008] File '/opt/customer/ci_workspace/sonar/10.1.0/TN/access/Application/src/com/panther/ph/access/persistence/cocobase/AccessBP.java' is ignored. It is not located in module basedir '/opt/customer/ci_workspace/sonar/10.1.0/TN/build/sonar'.
I have mentioned below property in my pom.xml
"/opt/customer/ci_workspace/sonar/10.1.0/TN
../../access/Application/src"

The base directory is where your POM is located and your analysis launched.
The problem is that in the POM, you are referring to a source folder that is not located in a sub-folder of the base directory. This is not supported in SonarQube - and this is actually not a standard structure for source code.

#Fabrice: The issue was someone had made some changes in repository which made our sonar-maven-plugin degrade to 2.0 version from 2.6 due to which it has failed.
#Everyone: If you are facing similar issue please check your sonar-maven-plugin is at least 2.6 version.

Related

Viewing version source for multi release JAR (MRJAR)

I'm trying to attach the Java 9 or Java 11 source for some projects released as MRJARs, namely jersey-container-jetty-http-3.0.2 and junit-platform-commons-1.4.0.
Looking at the jersey-container-jetty-http-3.0.2-sources.jar file in my ~/.m2/repository there is no META-INF/versions directory and the .java files in standard package locations are for Java 8 (pre module system). This is also the case if I unpack https://repo1.maven.org/maven2/org/glassfish/jersey/containers/jersey-container-jetty-http/3.0.2/jersey-container-jetty-http-3.0.2-sources.jar
This is a big bummer for my debugger :(
I was able to download the full source code from https://github.com/eclipse-ee4j/jersey/releases/tag/3.0.2, and it contains the following directories, with source:
containers/jetty-http/src/main/java11
containers/jetty-http/src/main/java8
I thought maybe this was just a Jersey problem, but looking at junit-platform-commons-1.4.0 I see a similar issue. Neither my ~/.m2/repository nor https://repo1.maven.org/maven2/org/junit/platform/junit-platform-commons/1.4.0/junit-platform-commons-1.4.0-sources.jar contain code for any java 9+ version but the release JAR contains /META-INF/versions/9/org/junit/platform/commons/util/ModuleUtils.class.
So my question: Is including source for multiple Java versions supported by Maven? If so, where are the Java 9+ source files be located?
The maven-source-plugin:jar goal which:
[...] bundles all the sources into a jar archive.
doesn't mention MRJAR explicitely but it has the parameter:
Name
Description
<includes>
List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.

File 'someFile.java' is ignored. It is not located in project basedir 'D:\HybrisSuites\HYBRISCOMM6400P\hybris\bin\platform'

Recently we were migrated SonarQube-6.3 to SonarQube7.9. From the Hybris side we are using sonar.xml is ant build file.
When we ran the sonar via ant command is ant sonar
we are getting the below issues.
[sonar:sonar] File 'someFile.java' is ignored. It is not located in project basedir 'D:\HybrisSuites\HYBRISCOMM6400P\hybris\bin\platform'.
based on the sonar.xml, we are mentioned the sonar properties in local.properties file.
sonar.projectName=TE
sonar.projectKey=TE
sonar.projectVersion=1.0
sonar.verbose=true
sonar.language=java
sonar.sourceEncoding=UTF-8
sonar.scm.disabled=True
sonar.host.url=http://localhost:8000
sonar.java.source=1.8 sonar.excludedExtensions=core,testweb,b2bacceleratoraddon,hystrixaddon,oauth2,embeddedserver,tomcatembeddedserver,platformbackoffice,voucherbackoffice,backofficesolrsearch,pcmbackoffice,promotionsbackoffice,ticketsystembackoffice,adaptivesearch,ordercalculation,webservicescommons,solrfacetsearchbackoffice,basecommercebackoffice,ruleengine,ruleengineservices,ruledefinitions,ruleenginebackoffice,b2bcommercefacades,b2bapprovalprocessfacades,droolsruleengineservices,promotionengineservices,promotionenginebackoffice,couponservices,couponwebservices,couponfacades,couponbackoffice,rulebuilderbackoffice,solrserver,commerceservicesbackoffice,customersupportbackoffice,adaptivesearchbackoffice,adaptivesearchsolr,warehousing,commerceorgaddon,paymetric,scripting,paymentstandard,mediaweb,maintenanceweb,deliveryzone,commons,processing,impex,validation,catalog,europe1,platformservices,workflow,hac,comments,advancedsavedquery,springintegrationlibs,ldap,hmc,virtualjdbc,cockpit,admincockpit,reportcockpit,platformhmc,productcockpit,customerreview,sapcoretest,sapcoreodata,sapcore,sapcorejco,sapcorejcorec,sapcorebol,advancedexport,backoffice,datahubbackoffice,mcc,wishlist,mediaconversion,solrfacetsearch,solrfacetsearchhmc,voucher,promotions,basecommerce,ticketsystem,cms2,cms2lib,btg,cmscockpit,btgcockpit,b2bcommerce,payment,commerceservices,b2bapprovalprocess,commercewebservicescommons,cscockpit,acceleratorservices,b2bacceleratorservices,acceleratorcms,commercefacades,acceleratorfacades,acceleratorstorefrontcommons,b2bacceleratorfacades,addonsupport,sapcoreaddon,captchaaddon,liveeditaddon,commercesearch,commercesearchhmc,commercesearchbackoffice,datahubadapter,sapcoreconfiguration,sapmodel,sapproductavailability,sapproductavailabilityhmc,b2bsapproductavailability,sappricingbol,sappricinghmc,sappricing,sappricingproductcarouseladdon,b2bsappricing,sapcustomerb2c,sapcustomerb2b,sapmodelhmc,saporderexchange,saporderexchangeb2b,sapcoreconfigurationhmc,sapproducthmc,sapcoreconfigurationbackoffice,multipaymentmode,amazonpay,codpayment,bspay,paypalservice,acceleratorcmshmc,warehousingwebservices,npmancillary,acceleratorwebservicesaddon,commerceserviceshmc,yaddon,customerticketingfacades,consignmenttrackingservices,ordermanagementwebservices,ordermanagementaddon,sap,promotionenginesamplesaddon,cmsfacades,consignmenttrackingfacades,ordermanagementfacade,warehousingfacade,samlsinglesignon,ycommercewebservices,consignmenttrackingaddon,ycommercewebservices,ycommercewebserviceshmc,acceleratorserviceshmc,customerticketingaddon,orderselfserviceaddon,asynchronousOM,saporderexchangehmc,saporderexchangebackoffice
sonar.global.exclusions= **/gensrc/**/*.java ,**/mobile/**/*.java,**/v1/**/*.java
sonar.exclusions=**/gensrc/**/*.java ,**/mobile/**/*.java,**/v1/**/*.java
sonar.sources=D:/HybrisSuites/HYBRISCOMM6400P/hybris/bin/custom/te/tecore/src
sonar.java.binaries=D:/HybrisSuites/HYBRISCOMM6400P/hybris/bin/custom/te/tecore/classes
Can you please let me know is there any properties i missed?
This will only scan under the base directory, so all files that are not under the base directory will be ignored
sonar.projectBaseDir=D:\HybrisSuites\HYBRISCOMM6400P\hybris\bin\platform

Sonarqube invalid value for java binaries

I'm trying to upload my project to a remote sonarqube server.
This is the command I run sonar scanner:
sonar-scanner -Dsonar.projectKey=my-project -Dsonar.host.url=https://xxxx:9000 -Dsonar.login=the-secret-key -Dsonar.java.binaries=**/target/classes
but it throws the error on java.binaries.
INFO: Configured Java source version (sonar.java.source):
none
INFO: JavaClasspath initialization
ERROR: Invalid value for sonar.java.binaries
INFO: ------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------
INFO: Total time: 20.276s
INFO: Final Memory: 10M/161M
INFO: ------------------------------------------------------
------------------
ERROR: Error during SonarQube Scanner execution
No files nor directories matching **/target/classes
I tried different values like ./target, /target/, /target/classes (where the jar is being stored). However, I am encountering this error of not found. (even though the directory exists)
By running sonar:sonar on my IDE and maven sonar:sonar on my terminal would send over the result to sonarqube, but my goal is to include this command in my jet-steps
Very old post but may help someone. I had similar issue and below configuration worked for me:
sonar.sources=src/main/java
sonar.java.binaries=target/classes
We also experienced a similar issue on our project (Maven multimodule), and for us the following configuration made things work:
sonar.java.binaries=.
sonar.java.source=8
sonar.sources=.
PS Java source is just for reference, it should not matter to fix the issue.
In my case, Im working with gradle, and we have subaplications, we are using sonarqube plugin from azure. I have to adapt to find binaries like this way:
sonar.java.binaries=./streamHubAndroidSDK/build/**,./nota/build/**,./app/build/**
But later I found that its better to define like this:
sonar.java.binaries=**/build/**
I can find this first building Android-Gradle project locally, and looking for all .class generated with bash:
find . -path '*/build/*.class' | xargs | tr ' ' ','

Common maven repository for GitLab CI

I hope someone can help me with a simple setup of maven CI scripts for GitLab.
I tried to search stackoverflow and google, which results in several questions and answers, but either they seem to be completely different or not that I understand them.
I have a simple setup of two projects. project B depends on project A (= pom packaging).
I have in the runner configuration /etc/gitlab-runner/config.toml the line with the volumes added
[[runners]]
...
[runners.docker]
...
volumes = ["/cache", "/.m2"]
...
my .gitlab-ci.yml for both projects look like this
image: maven:3.6.1-jdk-12
cache:
paths:
- /.m2/repository
- target/
variables:
MAVEN_OPTS: "-Dmaven.repo.local=/.m2/repository"
maven_job:
script:
- mvn clean install
with this - the first project builds correctly and I can see that the caching is working, as it does not download all maven related plugins for building the project, when executed again and again.
It also states
[INFO] Installing /builds/end2end/projectA/pom.xml to /.m2/repository/de/end2end/projectA/0.4.4-SNAPSHOT/projectA-0.4.4-SNAPSHOT.pom
It reports though at the end
WARNING: /.m2/repository: not supported: outside build directory
WARNING: /.m2/repository/classworlds: not supported: outside build directory
WARNING: /.m2/repository/classworlds/classworlds: not supported: outside build directory
WARNING: /.m2/repository/classworlds/classworlds/1.1-alpha-2: not supported: outside build directory
WARNING: /.m2/repository/classworlds/classworlds/1.1-alpha-2/_remote.repositories: not supported: outside build directory
[...]
When executing projectB, the job fails with the info, that it cannot find projectA.
So - what is wrong with the configuration of the runner / .gitlab-ci.yml files ?
I tried
cache:
paths:
- .m2/repository
which removes the warnings, but then the projectA gets in its local .m2 installed
[INFO] Installing /builds/end2end/projectA/pom.xml to /builds/end2end/projectAt/.m2/repository/de/end2end/projectA/0.4.4-SNAPSHOT/projectA-0.4.4-SNAPSHOT.pom
and projectB fails with the same error as above.
In fact, as described in gitlab doc, you use the dynamic storage so the volume is shared between subsequent runs of the same concurrent job for one project. I you want to share data between projects you must use the host-bound storage.
For the warning, the cache is only for working directory, so absolute path like /.m2/repository is not supported. In your case, you don't have to use cache for maven repository because you use a volume.

Unable to build maven project, pom.xml file not found

We recently lost (i.e they died after SAN failure) build VMs for an inhouse application. Unfortunately, these VMs were never backed up.
The devs that set this environment up have moved on and now I'm trying get these VMs going again as mods are required to this inhouse application. I'm a sys admin not a developer and this is proving harder than I thought...
The VMs that died were a TeamCity server and an Artifactory server.
I've built a new VM with both TeamCity and Artifactory (it should be lightly loaded enough to handle it). I have TeamCity talking to the git repo but when I try and build the project, I get
Non-readable POM /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430/webview/pom.xml: /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430/webview/pom.xml (No such file or directory)
Looking on the file system, indeed there is no pom.xml file at /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430/webview. There is however a pom.xml file in /srv/teamcity/10.0.4/buildAgent/work/b20d5a085d491430.
Any pointers on how to get Maven to look one directory up for this file?
Thanks
Edit:
Apologies all, I just found that I hadn't correctly defined the "VCS Root", I done that now and am getting further although the project still doesn't build. I'll poke it some more and see how I go.
I just found that I hadn't correctly defined the "VCS Root".
I faced similar issue. Solution is: Please check the module name in parent POM and child pom, both name should be same.
Adding to that Teamcity build using maven thrown me same kind of error with the below message
The project (/opt/buildagent/work/d1df6864f98d2599/pom.xml) has 1 error
Non-readable POM /opt/buildagent/work/d1df6864f98d2599/pom.xml: /opt/buildagent/work/d1df6864f98d2599/pom.xml (No such file or directory)
for me it solved by creating VCSRoot configuration

Resources