DEV Community

Khoa Pham
Khoa Pham

Posted on • Updated on

How to use Sonarqube in Swift projects

Install Sonarqube

  • Download Sonarqube for macOS
  • Put it in ~/sonarqube
  • Run localhost server ~/sonarqube/bin/macosx-universal-64/ console
  • Login http://localhost:9000 with admin/admin
  • Create new project

Install Sonar scanner

  • Download for macOS 64 bit
  • Put it in ~/sonarscanner
  • export PATH=$PATH:/Users/khoa/sonarscanner/bin
  • Go to project, create
# must be unique in a given SonarQube instance
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=My App

# Path is relative to the file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set. 

# Encoding of the source code. Default is default system encoding
  • Run sonar-scanner

Install swift plugin


  • Update
sonar.swift.appScheme=MyApp Staging
sonar.swift.simulator=platform=iOS Simulator,name=iPhone Xʀ
  • Run chmod +x
  • Run ./


failed with error code: 64

When run ./

xcodebuild: error: ''MyApp.xcodeproj'' does not exist.
2019-04-29 12:10:17.486 defaults[4134:569992]
Domain CFBundleShortVersionString does not exist
.Extracting Xcode project informationxcodebuild: error: option 'Destination' requires at least one parameter of the form 'key=value'

👉 Remove quotes in
👉 Modify, add these before Check for mandatory parameters section

Surround by double quotes


😢 Does not work
👉 Need to create a scheme name without space

Error code 65

👉Specify team in Xcode project


Need double quotes


Use equal sign =


instead of space ' '

-destination "$destinationSimulator"

Metric 'files' should not be computed by a Sensor

When run sonar-scanner

11:01:14.406 INFO: Sensor JaCoCo XML Report Importer [jacoco]
11:01:14.409 DEBUG: No reports found
11:01:14.409 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
11:01:14.409 INFO: Sensor SwiftLint [backelitesonarswiftplugin]
11:01:14.417 INFO: Sensor SwiftLint [backelitesonarswiftplugin] (done) | time=8ms
11:01:14.417 INFO: Sensor Tailor [backelitesonarswiftplugin]
11:01:14.418 INFO: Sensor Tailor [backelitesonarswiftplugin] (done) | time=1ms
11:01:14.418 INFO: Sensor OCLint [backelitesonarswiftplugin]
11:01:14.419 INFO: Sensor OCLint [backelitesonarswiftplugin] (done) | time=1ms
11:01:14.419 INFO: Sensor FauxPas [backelitesonarswiftplugin]
11:01:14.419 INFO: Sensor FauxPas [backelitesonarswiftplugin] (done) | time=0ms
11:01:14.419 INFO: Sensor Swift Squid [backelitesonarswiftplugin]
11:01:14.526 INFO: ------------------------------------------------------------------------
11:01:14.526 INFO: ------------------------------------------------------------------------
11:01:14.527 INFO: Total time: 6.180s
11:01:14.603 INFO: Final Memory: 25M/566M
11:01:14.603 INFO: ------------------------------------------------------------------------
11:01:14.603 ERROR: Error during SonarQube Scanner execution
java.lang.UnsupportedOperationException: Metric 'files' should not be computed by a Sensor
    at org.sonar.scanner.sensor.DefaultSensorStorage.saveMeasure(

👉Install maven
Edit and SwiftSquidSensor, remove line with CoreMetrics.FILES
Run export PATH=$PATH:/Users/khoa/apache-maven/bin
Run ./
Or ~/apache-maven/bin/mvn clean install

🎉 Built jar is in sonar-swift-plugin/target/backelite-sonar-swift-plugin-0.4.4.jar, copy back to extensions/plugins

How to enable SwiftLint as default profile 🤔

👉 Need to close current Sonar tab and restart server

Testing failed: unable to attach DB

Modify to add -UseModernBuildSystem=NO to buildCmd+=(-destination

slather No coverage directory found

👉 Enable coverage option in scheme -> Test

Optional: declare .slather.yml file

Unable to execute SonarQube

14:53:23.251 ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
    at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(

👉Start sonar server

❤️ Support my app ❤️


Top comments (1)

mercury77 profile image
mercury77 • Edited


I've read the guide , but maybe I've done some mistakes ,can you hepl me on this ?

Creating directory sonar-reports/
Building & extracting Xcode project information

  • xcodebuild clean build-for-testing -workspace MyApp.xcworkspace -scheme MyApp '-destination="platform=iOS Simulator,name=iPhone 8,OS=11.4"' -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO
    2020-03-19 15:47:08.898 xcodebuild[13418:30032] Error writing xctestrun file: Error Domain=NSCocoaErrorDomain Code=4 "The folder “MyApp_iphoneos13.2-arm64e.xctestrun” doesn’t exist." UserInfo={NSFilePath=/var/root/Library/Developer/Xcode/DerivedData/MyApp-fjbdzxyjiiznisbynvxkrvwqxovi/Build/Products/MyApp_iphoneos13.2-arm64e.xctestrun, NSUserStringVariant=Folder, NSUnderlyingError=0x7fc9599b9dc0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

  • returnValue=65

  • set +x
    ERROR - Command 'xcodebuild clean build-for-testing -workspace MyApp.xcworkspace -scheme MyApp -destination="platform=iOS Simulator,name=iPhone 8,OS=11.4" -destination-timeout 360 COMPILER_INDEX_STORE_ENABLE=NO' failed with error code: 65