Setting projectKey at the command line for a Maven build has no effect

Attempting to override projectKey via the command line appears to have no effect; the published project is still using a name generated from the Java namespace. What is the recommended approach here? More details:

Using Sonar Maven plugin 3.8.0.2131, initiating a scan from Jenkins.

I’m invoking this using Artifactory’s Maven Jenkins plugin and setting the opts field. In my logs it seems the correct command is being executed (notice -Dsonar.projectKey):

Executing command: "/opt/java/openjdk/bin/java" "-classpath" "/usr/local/bin/apache-maven-3.6.3/boot/*" "-Dmaven.home=/usr/local/bin/apache-maven-3.6.3" "-Dmaven.conf=/usr/local/bin/apache-maven-3.6.3/conf" "-DbuildInfoConfig.propertiesFile=/home/jenkins/agent/workspace/message-copier_PR-1/templates@tmp/artifactory/buildInfo7812084656265986842.properties" "-Dm3plugin.lib=/home/jenkins/agent/workspace/message-copier_PR-1/templates@tmp/artifactory/cache/artifactory-plugin/3.8.1" "-Dclassworlds.conf=/home/jenkins/agent/workspace/message-copier_PR-1/templates@tmp/artifactory/classworlds3939416916739384047conf" "-Dmaven.multiModuleProjectDirectory=/home/jenkins/agent/workspace/message-copier_PR-1/templates" "-Dsonar.projectKey=message-copier-templates" "-Dsonar.projectName=message-copier-templates" "-Dsonar.projectVersion=1.0-PR-1-SNAPSHOT" "-Dsonar.go.golangci-lint.reportPaths=" "-Dsonar.go.tests.reportPaths=" "-Dsonar.go.coverage.reportPaths=**/cover.out" "-Dsonar.jacoco.reportPaths=build/jacoco/*.exec" "org.codehaus.plexus.classworlds.launcher.Launcher" "-f" "pom.xml" "sonar:sonar" 

I may have resolved this through the Artifactory plugin that is launching the Maven build: I’ve added comments to this similar-looking (old) ticket:

Passing the arguments as part of the Maven goal appears to work, even though the Jenkins logs imply the opposite.

I can also confirm that the following command works fine locally:

mvn "-Dmaven.multiModuleProjectDirectory=." "-Dsonar.login=REDACTED" "-Dsonar.projectKey=message-copier-templates" "-Dsonar.projectName=message-copier-templates" "-Dsonar.projectVersion=1.0-PR-1-SNAPSHOT" "-Dsonar.go.golangci-lint.reportPaths=" "-Dsonar.go.tests.reportPaths=" "-Dsonar.go.coverage.reportPaths=**/cover.out" "-Dsonar.jacoco.reportPaths=build/jacoco/*.exec" "sonar:sonar"
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.