Sonar error : Wrong source path use by the analyser - java

I run the command below with GitLab CI / CD:
mvn -s /etc/gitlab-runner/maven/settings-maven.xml --batch-mode test sonar:sonar
-Dsonar.java.source=1.8
-Dsonar.host.url=${SONARHOST}
-Dsonar.projectKey=${SONARKEY}
-Dsonar.projectName=${SONARNAME}
-Dsonar.projectVersion=${SONARVERSION}
-Dsonar.sources=myproject_core/src/main/java,myproject_service/src/main/java,myproject_persistance/src/main/java
-Dsonar.language=java
-Dsonar.java.binaries=myproject_core/target/classes,myproject_service/target/classes,myproject_persistance/target/classes
-Dsonar.java.libraries=**/*.jar
-Dsonar.java.coveragePlugin=jacoco
-Dsonar.surefire.reportPaths=myproject_core/target/surefire-reports,myproject_service/target/surefire-reports,myproject_persistance/target/surefire-reports
-Dsonar.junit.reportPaths=myproject_core/target/surefire-reports,myproject_persistance/target/surefire-reports,myproject_service/target/surefire-reports
-Dsonar.verbose=true
-Dsonar.binaries=myproject_core/target/classes,myproject_service/target/classes,myproject_persistance/target/classes
-Dsonar.jacoco.reportPaths=myproject_core/target/jacoco.exec,myproject_service/target/jacoco.exec,myproject_persistance/target/jacoco.exec
-Dsonar.exclusions=**/*Test*/**
-Dsonar.tests=myproject_core/src/test,myproject_service/src/test,myproject_persistance/src/test
So, I want to analyse 3 project core, service and persistance (I have 7 modules in my project)
myproject-parent
myproject-core
myproject-persistance
myproject-service
myproject- ...
But, I have this error :
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project myproject-parent: The directory '/builds/git-myproject/myproject-parent/**myproject_persistance/myproject_core**/src/main/java' does not exist for Maven module fr.xxx.xxx.myproject:myproject_persistance:jar:1.1. Please check the property sonar.sources -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project myproject-parent: The directory '/builds/git-myproject/myproject-parent/myproject_persistance/myproject_core/src/main/java' does not exist for Maven module fr.xxx.xxx.myproject:myproject_persistance:jar:1.1. Please check the property sonar.sources
On this sonarqube error, i can see that in the path, module persistance is include on module core, but this is not the case
I'm looking for why but I can't find. Have you ever had this problem ?

Related

Could not find artifact spring-boot-thin-layout:jar:1.0.27.RELEASE

More info of the error:
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:repackage (repackage) on project HelloWorldProject: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:repackage failed: Plugin org.springframework.boot:spring-boot-maven-plugin:2.4.3
with org.springframework.boot.experimental
Oh thanks, I see in the mvn repo that version 1.0.26.RELEASE is the highest version existing for spring-boot-thin-layout.

Can't Authenticate Maven to Access Azure Artifacts from ADO Pipeline

I have a azure pipeline that runs in the cloud and in there, I basically want to run a Blackduck scan. To make it easy, the blackduck task runs a maven command to build the dependency tree. In order to do so, it scans all the dependencies in my pom.xml.
I currently have 2 feeds in Azure DevOps. 1 feed that store external libraries and 1 to store internal libraries developed in house. All the dependencies that are external, the maven command is able to retrieve but not the internal one. I keep getting a 401 Unauthorized error.
I have updated my pom.xml to include the credentials to connect to azure artifact as shown here. I have also updated the settings.xml file to include the connection as well. Before the maven command is run, I have added the Maven authenticate task
Yml pipeline:
- task: PowerShell#2
displayName: "Modify Settings.xml"
inputs:
targetType: 'inline'
script: |
$xmlPom = [xml]"<server>
<id>Pack-All</id>
<username>Bob</username>
<password>$(ado.pat)</password>
</server>"
$file = "settings.xml"
$origin = "$(M2_HOME)\conf"
$xdoc = new-object System.Xml.XmlDocument
$fileXml = resolve-path(“$origin\$file”)
$xdoc.load($fileXml)
$xdoc.settings.servers.AppendChild($xdoc.ImportNode($xmlPom.server, $true))
$xdoc = [xml] $xdoc.OuterXml.Replace(" xmlns=`"`"", "")
$xdoc.Save(“$origin\$file”)
- task: MavenAuthenticate#0
displayName: 'Maven Authenticate'
inputs:
artifactsFeeds: 'Pack-All'
- task: SynopsysDetectTask#2
displayName: "Run Black Duck analysis"
condition: and(succeeded(), eq('${{ parameters.blackduck }}', 'true'))
continueOnError: true
inputs:
Products: 'BD'
BlackDuckService: 'Black Duck'
DetectVersion: 'latest'
DetectArguments: '--detect.project.name=$(Build.Repository.Name)Test --detect.binary.scan.file.path=$(Build.SourcesDirectory)\app.war --detect.maven.build.command=-DmavenFeedAuthenticate=true'
Maven command that the Blackduck task executes:
C:\ProgramData\chocolatey\lib\maven\apache-maven-3.6.3\bin\mvn.cmd -DmavenFeedAuthenticate=true dependency:tree -T1
Error Log:
[ERROR] Failed to execute goal on project dimload-ms-app-agg: Could not resolve dependencies for project ca.test-ms-app-agg:war:0.0.1-SNAPSHOT: Failed to collect dependencies at ca.cn.boot:helpers:jar:0.4.28950: Failed to read artifact descriptor for ca.test.boot:helpers:jar:0.4.28950: Could not transfer artifact ca.test.boot:helpers:pom:0.4.28950 from/to Test-All (https://pkgs.dev.azure.com/Test-Int/_packaging/Pack-All/maven/v1): Authentication failed for https://pkgs.dev.azure.com/Test-Int/_packaging/Pack-All/maven/v1/ca/test/boot/helpers/0.4.28950/helpers-0.4.28950.pom 401 Unauthorized -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
From your Yaml Sample, you have added the MavenAuthenticate task. This task will automatically generate a settings.xml for the target feed.
This file exists in the path xxx\.m2\settings.xml
So you don't need to add this file(settings.xml)manually. This can also help you simplify your code.
Authentication failed for https://pkgs.dev.azure.com/.... 401 Unauthorized
The possible cause of this issue is that the build service account does not have sufficient permissions for the feed.
You could try the following steps:
Navigate to Artifacts ->Target Feed ->Feed Settings -> Permission.
Set the Project Build Service(ProjectName Build Service(OrganizationName)) As Contributor role within the target feed.
Or you could enable the option Allow Project-Scoped Builds.
On the other hand, from the feed URL, it seems to be an Organization-Scope feed.
You could check the Limit job authorization scope to current project for non-release pipelines option is Enabled in Project Settings -> Pipelines.
You could try to disable the option.
Note: To disable this option, you need to disable the option in Organization Settings-> Settings first. Then you could disable the option in Project level.

How do I use "projectVersionPolicyId" in Maven Release Plugin?

There is a parameter projectVersionPolicyId in many mojos of Maven Release Plugin, e.g. http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#projectVersionPolicyId. However, it seems that they provided no examples of how I can use it.
When I try:
$ mvn --batch-mode release:prepare -DprojectVersionPolicyId=foo
It shows an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M1:prepare (default-cli) on project maven-release-test: Policy 'foo' is unknown, available: [default] -> [Help 1]
It looks like that there only 1 available policy (which is default). Is there any way to add more possible policies?
You can use SemVerVersionPolicy as well

Failed to create parent directories for tracking file .lastUpdated

I've added com.spotify:dockerfile-maven-plugin:1.4.3 to my POM and it
s unable to complete because of the following u
[INFO] --- dockerfile-maven-plugin:1.4.3:build (default) # server-api
--- Downloading: https://repo.maven.apache.org/maven2/com/fasterxml/jackson/module/jackson-modules-base/2.9.4/jackson-modules-base-2.9.4.pom
[WARNING] Failed to create parent directories for tracking file
/home/alex/.m2/repository/com/fasterxml/jackson/module/jackson-modules-base/2.9.4/jackson-modules-base-2.9.4.pom.lastUpdated
Which, in turn, causes:
[ERROR] Failed to execute goal
com.spotify:dockerfile-maven-plugin:1.4.3:build (default) on project
server-api: Execution default of goal
com.spotify:dockerfile-maven-plugin:1.4.3:build failed: Plugin
com.spotify:dockerfile-maven-plugin:1.4.3 or one of its dependencies
could not be resolved: Failed to collect dependencies at
com.spotify:dockerfile-maven-plugin:jar:1.4.3 ->
com.spotify:docker-client:jar:shaded:8.11.4 ->
com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.9.4 ->
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.4:
Failed to read artifact descriptor for
com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.4:
Could not transfer artifact
com.fasterxml.jackson.module:jackson-modules-base:pom:2.9.4 from/to
central (https://repo.maven.apache.org/maven2):
/home/alex/.m2/repository/com/fasterxml/jackson/module/jackson-modules-base/2.9.4/jackson-modules-base-2.9.4.pom.part.lock
(No such file or directory) -> [Help 1]
It had happened for us because some part of /.m2/repository was not having correct permissions.
I removed ~/.m2/ and it worked
I tried changing permissions of .m2 folder and repository. No luck.
Finally updated maven from 3.6.0 to 3.6.3 (latest) and it worked!
Changing the file permissions using the following command:
sudo chmod 777 repository
solves the problem

Maven build of Saiku open source project fails second time after no changes

I was doing a build yesterday for the second time of an open source project (Saiku) – I have made no changes to the POM.XML or any of the libraries/jars. The build succeeded a few days ago but now fails. The following pastebin shows the output. The errors are of two types – failure to delete /clean project, and cannot find artifact. Does anyone have any troubleshooting tips?
http://pastebin.com/g2bpAtMS
error type 1
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project saiku-core: Failed to clean project: Failed to delete /usr/local/.m2/repository/saiku/saiku-core/target/javadoc-bundle-options/javadoc-options-javadoc-resources.xml
error Type 2
- [ERROR] The build could not read 1 project -> [Help 1]
- [ERROR] The project org.saiku:saiku-webapp:2.2-SNAPSHOT (/usr/local/.m2/repository/saiku/saiku-webapp/pom.xml) has 1 error
- [ERROR] Non-resolvable parent POM: Could not find artifact org.saiku:saiku-core:pom:2.2-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 3, column 10 -> [Help 2]
Are you building within your local repo? That would be bad.
I get similar errors because, I think, my virus checker locks a file underneath the target/ directory and clean cannot delete the directory. I delete the directory manually and resume the build.
Failed to delete /usr/local/.m2/repository/saiku/saiku-core/target/javadoc-bundle-options/javadoc-options-javadoc-resources.xml
You have locked this file. Close every program which could have opened it.
Failed to delete /usr/local/.m2/repository/saiku/saiku-ui/target/classes/routers/QueryRouter.js
Idem for this file.
/usr/local/.m2/repository/saiku/saiku-server/target/saiku-server-foodmart-2.2-SNAPSHOT.tar.gz
Idem for this file.
Could not find artifact org.saiku:saiku-core:pom:2.2-SNAPSHOT and 'parent.relativePath' points at wrong local POM
It seems you have changed something : Maven does not find the parent pom referenced by relativePath attribute.
Check these errors, you always many errors.
I've fixed that by setting relativePath in pom.xml of saiku-webapp:
<parent>
<artifactId>saiku-core</artifactId>
<groupId>org.saiku</groupId>
<version>2.6-SNAPSHOT</version>
<relativePath>../saiku-core/pom.xml</relativePath>
</parent>

Categories

Resources