다음 파일을 다운로드합니다.
- SonarQube 5.6 (LTS *) / Jun. 3, 2016 - sonarqube-5.6.zip
- SonarQube Scanner 2.6.1 / Compatible with SonarQube 4.5.4+ (LTS) - sonar-scanner-2.6.1.zip
또한 SonarCube 5.6 실행을 위해서는 자바 8 이상의 버전이 필요합니다.
SonarCube를 설치하였다면, bin/[플랫폼]/sonar.sh 파일을 실행합니다.
$ ./sonar.sh Usage: ./sonar.sh { console | start | stop | restart | status | dump }
SonarCube 실행 : console 파라미터 사용
$ ./sonar.sh console Running SonarQube... wrapper | --> Wrapper Started as Console wrapper | Launching a JVM... jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. jvm 1 | jvm 1 | WrapperSimpleApp: Unable to locate the class org.sonar.application.App: java.lang.UnsupportedClassVersionError: org/sonar/application/App : Unsupported major.minor version 52.0 jvm 1 | jvm 1 | WrapperSimpleApp Usage: jvm 1 | java org.tanukisoftware.wrapper.WrapperSimpleApp {app_class} [app_arguments] jvm 1 | jvm 1 | Where: jvm 1 | app_class: The fully qualified class name of the application to run. jvm 1 | app_arguments: The arguments that would normally be passed to the jvm 1 | application. wrapper | <-- Wrapper Stopped
- 현상 : java.lang.UnsupportedClassVersionError: org/sonar/application/App : Unsupported major.minor version 52.0
- 해결책 : PATH에 자바 8 디렉토리 설정
SonarCube 실행 : 자바 8로 실행
$ ./sonar.sh console Running SonarQube... wrapper | --> Wrapper Started as Console wrapper | Launching a JVM... jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved. jvm 1 | jvm 1 | 2016.06.23 14:31:39 INFO app[o.s.a.AppFileSystem] Cleaning or creating temp directory /app/sonar/cube/5.6/temp jvm 1 | 2016.06.23 14:31:39 INFO app[o.s.p.m.JavaProcessLauncher] Launch process[es]: /app/java/jdk1.8.0_60/jre/bin/java -Djava.awt.headless=true -Xmx1G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=/app/sonar/cube/5.6/temp -javaagent:/app/java/jdk1.8.0_60/jre/lib/management-agent.jar -cp ./lib/common/*:./lib/search/* org.sonar.search.SearchServer /app/sonar/cube/5.6/temp/sq-process4848100448401589859properties jvm 1 | 2016.06.23 14:31:50 INFO app[o.s.p.m.Monitor] Process[es] is up jvm 1 | 2016.06.23 14:31:50 INFO app[o.s.p.m.JavaProcessLauncher] Launch process[web]: /app/java/jdk1.8.0_60/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false -Djruby.compile.invokedynamic=false -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true -Djava.io.tmpdir=/app/sonar/cube/5.6/temp -javaagent:/app/java/jdk1.8.0_60/jre/lib/management-agent.jar -cp ./lib/common/*:./lib/server/*:/app/sonar/cube/5.6/lib/jdbc/h2/h2-1.3.176.jar org.sonar.server.app.WebServer /app/sonar/cube/5.6/temp/sq-process1214224831093130358properties jvm 1 | 2016.06.23 14:32:13 INFO app[o.s.p.m.Monitor] Process[es] is stopping jvm 1 | 2016.06.23 14:32:14 INFO app[o.s.p.m.Monitor] Process[es] is stopped wrapper | <-- Wrapper Stopped
- 현상 : 기동 후 바로 중지
- 해결책 : logs 디렉토리 내 로그 확인 결과 다음과 같이 파일 시스템 Disk Space 부족, DIsk Space 확보
Caused by: java.io.IOException: No space left on device at sun.nio.ch.FileDispatcherImpl.pwrite0(Native Method) ~[na:1.8.0_60] at sun.nio.ch.FileDispatcherImpl.pwrite(FileDispatcherImpl.java:66) ~[na:1.8.0_60] at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:89) ~[na:1.8.0_60] at sun.nio.ch.IOUtil.write(IOUtil.java:51) ~[na:1.8.0_60] at sun.nio.ch.FileChannelImpl.writeInternal(FileChannelImpl.java:777) ~[na:1.8.0_60] at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:763) ~[na:1.8.0_60] at sun.nio.ch.FileChannelImpl.transferFromFileChannel(FileChannelImpl.java:635) ~[na:1.8.0_60] at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:707) ~[na:1.8.0_60] at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1147) ~[commons-io-2.4.jar:2.4] at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1091) ~[commons-io-2.4.jar:2.4] at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038) ~[commons-io-2.4.jar:2.4] at org.sonar.server.plugins.ServerPluginJarExploder.explode(ServerPluginJarExploder.java:58) ~[sonar-server-5.6.jar:na] ... 33 common frames omitted
SonarCube 재실행
ps -ef | grep sonar | grep java | grep -v grep sonar 1437 1435 1 16:50 pts/1 00:00:01 java -Djava.awt.headless=true -Xms3m -Xmx3m -Djava.library.path=./lib -classpath ../../lib/jsw/wrapper-3.2.3.jar:../../lib/sonar-application-5.6.jar -Dwrapper.key=2BYeY2oZ3BfUNweN -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.pid=1435 -Dwrapper.version=3.2.3 -Dwrapper.native_library=wrapper -Dwrapper.cpu.timeout=10 -Dwrapper.jvmid=1 org.tanukisoftware.wrapper.WrapperSimpleApp org.sonar.application.App sonar 1453 1437 36 16:50 pts/1 00:00:19 /app/java/jdk1.8.0_60/jre/bin/java -Djava.awt.headless=true -Xmx1G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=/app/sonar/cube/5.6/temp -javaagent:/app/java/jdk1.8.0_60/jre/lib/management-agent.jar -cp ./lib/common/*:./lib/search/* org.sonar.search.SearchServer /app/sonar/cube/5.6/temp/sq-process6751888188614891286properties sonar 1492 1437 61 16:50 pts/1 00:00:25 /app/java/jdk1.8.0_60/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djruby.management.enabled=false -Djruby.compile.invokedynamic=false -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.net.preferIPv4Stack=true -Djava.io.tmpdir=/app/sonar/cube/5.6/temp -javaagent:/app/java/jdk1.8.0_60/jre/lib/management-agent.jar -cp ./lib/common/*:./lib/server/*:/app/sonar/cube/5.6/lib/jdbc/h2/h2-1.3.176.jar org.sonar.server.app.WebServer /app/sonar/cube/5.6/temp/sq-process8058458551065492873properties
SonarCube의 기본 웹 포트는 9000입니다. 브라우저를 통해 9000 포트에 접속하면 웹 화면을 확인할 수 있습니다. 또한 다음과 같은 문구가 있습니다.
Embedded database should be used for evaluation purpose only The embedded database will not scale, it will not support upgrading to newer versions of SonarQube, and there is no support for migrating your data out of it into a different database engine.
그럼 이제 Scanner를 실행해 보겠습니다. bin 디렉토리에 sonar-scanner라는 파일이 있습니다.
$ ./sonar-scanner INFO: Scanner configuration file: /app/sonar/scanner/2.6.1/conf/sonar-scanner.properties INFO: Project root configuration file: NONE INFO: SonarQube Scanner 2.6.1 INFO: Java 1.8.0_60 Oracle Corporation (64-bit) INFO: Linux 2.6.32-279.el6.x86_64 amd64 INFO: User cache: /home/sonar/.sonar/cache INFO: Load global repositories INFO: Load global repositories (done) | time=607ms INFO: User cache: /home/sonar/.sonar/cache INFO: Load plugins index INFO: Load plugins index (done) | time=41ms INFO: Download sonar-csharp-plugin-5.0.jar INFO: Download sonar-java-plugin-3.13.1.jar INFO: Download sonar-scm-git-plugin-1.2.jar INFO: Download sonar-scm-svn-plugin-1.3.jar INFO: Download sonar-javascript-plugin-2.11.jar INFO: SonarQube server 5.6 INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent) INFO: Process project properties INFO: ------------------------------------------------------------------------ INFO: EXECUTION FAILURE INFO: ------------------------------------------------------------------------ INFO: Total time: 19.591s INFO: Final Memory: 40M/97M INFO: ------------------------------------------------------------------------ ERROR: Error during SonarQube Scanner execution ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources ERROR: ERROR: To see the full stack trace of the errors, re-run SonarQube Scanner with the -e switch. ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
이 오류의 해결책은 sonar-project.properties 파일을 생성하고 아래와 같이 sonar.projectKey, sonar.projectName 등의 속성을 설정하는 것입니다.
< sonar-project.properties 예제 >
# must be unique in a given SonarQube instance sonar.projectKey=my:project # this is the name displayed in the SonarQube UI sonar.projectName=My project sonar.projectVersion=1.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # Since SonarQube 4.2, this property is optional if sonar.modules is set. # If not set, SonarQube starts looking for source code from the directory containing # the sonar-project.properties file. sonar.sources=. # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8
그런데 SonarCube Scanner의 conf 디렉토리에 두어도 오류는 동일합니다. 과연 이 sonar-project.properties 파일은 어디에 두어야 하는 것일까요?
- 분석할 소스 위치에 sonar-project.properties 파일을 생성하고 설정한다.
- 분석할 소스 위치에서 sonar-scanner를 실행한다. (전제조건: PATH에 걸려있다, 따라서 어디에서도 실행된다)
이제 이렇게 정상 실행될 것입니다. 분석 대상 프로젝트는 "ossp"입니다.
$ sonar-scanner INFO: Scanner configuration file: /app/sonar/scanner/2.6.1/conf/sonar-scanner.properties INFO: Project root configuration file: /app/sonar/scanner/2.6.1/project/sonar-project.properties INFO: SonarQube Scanner 2.6.1 INFO: Java 1.8.0_60 Oracle Corporation (64-bit) INFO: Linux 2.6.32-279.el6.x86_64 amd64 INFO: User cache: /home/sonar/.sonar/cache INFO: Load global repositories INFO: Load global repositories (done) | time=461ms INFO: User cache: /home/sonar/.sonar/cache INFO: Load plugins index INFO: Load plugins index (done) | time=8ms INFO: SonarQube server 5.6 INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent) INFO: Process project properties INFO: Load project repositories INFO: Load project repositories (done) | time=209ms INFO: Load quality profiles INFO: Load quality profiles (done) | time=1704ms INFO: Load active rules INFO: Load active rules (done) | time=3203ms WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project. INFO: Publish mode INFO: ------------- Scan OSSP project INFO: Load server rules INFO: Load server rules (done) | time=613ms INFO: Base dir: /app/sonar/scanner/2.6.1/project INFO: Working dir: /app/sonar/scanner/2.6.1/project/.sonar INFO: Source paths: . INFO: Source encoding: UTF-8, default locale: en_US INFO: Index files INFO: 28 files indexed INFO: Quality profile for js: Sonar way INFO: JaCoCoSensor: JaCoCo report not found : /app/sonar/scanner/2.6.1/project/target/jacoco.exec INFO: JaCoCoItSensor: JaCoCo IT report not found: /app/sonar/scanner/2.6.1/project/target/jacoco-it.exec INFO: Sensor Lines Sensor INFO: Sensor Lines Sensor (done) | time=78ms INFO: Sensor JavaScriptSquidSensor INFO: 28 source files to be analyzed INFO: 7/28 files analyzed, current file: /app/sonar/scanner/2.6.1/project/ossp/resources/js/bootstrap/less.js INFO: 28/28 source files have been analyzed INFO: Sensor JavaScriptSquidSensor (done) | time=25334ms INFO: Sensor SCM Sensor INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it. INFO: Sensor SCM Sensor (done) | time=0ms INFO: Sensor org.sonar.plugins.javascript.lcov.UTCoverageSensor INFO: Sensor org.sonar.plugins.javascript.lcov.UTCoverageSensor (done) | time=0ms INFO: Sensor org.sonar.plugins.javascript.lcov.ITCoverageSensor INFO: Sensor org.sonar.plugins.javascript.lcov.ITCoverageSensor (done) | time=0ms INFO: Sensor Zero Coverage Sensor INFO: Sensor Zero Coverage Sensor (done) | time=200ms INFO: Sensor Code Colorizer Sensor INFO: Sensor Code Colorizer Sensor (done) | time=3ms INFO: Sensor CPD Block Indexer INFO: DefaultCpdBlockIndexer is used for js INFO: Sensor CPD Block Indexer (done) | time=1948ms INFO: Calculating CPD for 12 files INFO: CPD calculation finished INFO: Analysis report generated in 541ms, dir size=2 MB INFO: Analysis reports compressed in 364ms, zip size=884 KB INFO: Analysis report uploaded in 6291ms INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/ossp:project INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AVV8Vsdk5AW_CobCs0LV INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 50.569s INFO: Final Memory: 46M/228M INFO: ------------------------------------------------------------------------
그리고 9000번의 SonarCube 웹 화면에서 결과 확인이 가능합니다.
Dashboards.
특정 프로젝트 선택.
Bug.