使用Travis.CI设置SonarJava 4.12分析(字节码问题)

时间:2017-08-31 10:52:26

标签: java android sonarqube travis-ci

根据this,Sonarqube现在需要字节码才能正确检查Java代码。 我有一个工作的Travis CI + SonarQube工作流程,由于新的需求,现在已经打破了。

我在设置新工作流程时遇到了问题。

这是我得到的错误:

  

错误:SonarQube扫描程序执行期间出错   java.lang.IllegalStateException:没有文件或目录匹配' / home / travis / build / My_user_name / My_project_name / app / build / intermediates / classes /'       at org.sonar.java.AbstractJavaClasspath.getFilesFromProperty(AbstractJavaClasspath.java:93)       在org.sonar.java.JavaClasspath.init(JavaClasspath.java:49)       在org.sonar.java.AbstractJavaClasspath.getElements(AbstractJavaClasspath.java:281)       在org.sonar.java.SonarComponents.getJavaClasspath(SonarComponents.java:141)       在org.sonar.java.JavaSquid。(JavaSquid.java:83)       在org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:83)       在org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)       在org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)       在org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)       在org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)       在org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:78)       在org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:179)       在org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)       在org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)       在org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:261)       在org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:256)       在org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:245)       在org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)       在org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)       在org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)       在org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)       在org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)       在org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)       at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:119)       在org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116)       在org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:483)       在org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)       在com.sun.proxy。$ Proxy0.execute(未知来源)       在org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)       在org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)       在org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)       在org.sonarsource.scanner.cli.Main.execute(Main.java:74)       在org.sonarsource.scanner.cli.Main.main(Main.java:61)

我不知道Travis在哪里存储我的Android ByteCode文件或如何正确告诉SonarQube他们的位置。

修改 sonar-project.properties:

# must be unique in a given SonarQube instance
sonar.projectKey=key:dev
# sonar.branch=${branch}
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=name
sonar.projectVersion=1.40

# 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=app/src

sonar.java.binaries=app/build/intermediates/classes/

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

sonar.exclusions=R.java, /build
sonar.language=java

sonar.junit.reportsPath=build/outputs/androidTest-results/connected/

1 个答案:

答案 0 :(得分:0)

您使用sonar-project.properties文件表示您正在尝试使用SonarQube扫描仪进行分析。虽然这是通用的解决方案,但并非最适合所有情况。由于您已经在使用Gradle构建Android项目,因此我使用SonarQube Scanner for Gradle,它会自动了解您的字节代码和源文件的位置。