当前位置: 代码迷 >> Android >> 声纳运行器执行失败导致强制转换异常
  详细解决方案

声纳运行器执行失败导致强制转换异常

热度:58   发布时间:2023-08-04 12:46:54.0

配置了声纳工具(SonarQube,MySql数据库和Sonar-runner)后,我对Android项目进行了分析,没有任何问题。 但是,在安装了适用于声纳的Android插件并重复分析之后,此错误无法获取下一个错误:

INFO  - Preview mode
Load batch settings
User cache: /home/user/.sonar/cache
INFO  - Install plugins
INFO  - Exclude plugins: devcockpit, jira, pdfreport, views, report, buildstability, scmactivity, buildbreaker
INFO  - Create JDBC datasource for jdbc:h2:/home/user/workspace/myAndroidProject/.sonar/.sonartmp/preview1394469024394-0
INFO  - Initializing Hibernate
INFO  - Load project settings
INFO  - Apply project exclusions
INFO  - -------------  Scan myAndroidProject
INFO  - Load module settings
INFO  - Language is forced to java
INFO  - Loading technical debt model...
INFO  - Loading technical debt model done: 424 ms
INFO  - Configure Maven plugins
INFO  - Base dir: /home/user/workspace/myAndroidProject
INFO  - Working dir: /home/user/workspace/myAndroidProject/.sonar
INFO  - Source dirs: /home/user/workspace/myAdnroidProject/src
INFO  - Source encoding: UTF-8, default locale: en_EN
INFO  - Index files
INFO  - Included sources: 
INFO  -   src/**
INFO  - 116 files indexed
WARN  - Accessing the filesystem before the Sensor phase is deprecated and will not be supported in the future. Please update your plugin.
INFO  - Index files
INFO  - Included sources: 
INFO  -   src/**
INFO  - 116 files indexed
WARN  - Accessing the filesystem before the Sensor phase is deprecated and will not be supported in the future. Please update your plugin.
INFO  - Index files
INFO  - Included sources: 
INFO  -   src/**
INFO  - 116 files indexed
INFO  - Quality profile for java: Sonar way
INFO  - Sensor JavaSourceImporter...
INFO  - Sensor JavaSourceImporter done: 49 ms
INFO  - Sensor JavaSquidSensor...
INFO  - Java AST scan...
INFO  - 116 source files to be analyzed
INFO  - 116/116 source files analyzed
INFO  - Java AST scan done: 6693 ms
WARN  - Java bytecode has not been made available to the analyzer. The Depth of Inheritance Tree (DIT) metric, Response for Class (RFC) metric, Number of Children (NOC) metric, Lack of Cohesion (LCOM4) metric, deperecated dependencies metrics, UnusedPrivateMethod rule, RedundantThrowsDeclarationCheck rule, S1160 rule, S1217 rule are disabled.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 18.440s
Final Memory: 12M/357M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: org.sonar.api.resources.Directory cannot be cast to    org.sonar.api.resources.JavaPackage

我的sonar-project.properties文件是enxt:

#Required metadata
sonar.projectKey=mKey
sonar.projectName=myAndroidProject
sonar.projectVersion=1.0

# Paths to source directories.
# Paths are relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Do not put the "sonar-project.properties" file in the same directory with the source code.
# (i.e. never set the "sonar.sources" property to ".")
sonar.sources=src

# The value of the property must be the key of the language.
sonar.language=java

# Encoding of the source code
sonar.sourceEncoding=UTF-8

# Analysis mode
sonar.analysis.mode=preview


#Enables the Lint profile to analyze the code using the Lint rules.
#sonar.profile=Android Lint

我正在使用下一个环境:

  • SonarQube 4.2 RC1
  • 声纳运行者2.3
  • 数据库:MySQL
  • Ubuntu 12.04 LTS
  • Java 1.7

我尝试卸载Android插件,但问题仍然存在。 我发现解决该问题的独特方法是删除数据库和用户,然后再次创建它们。

如所述,Android插件尚未与SonarQube 4.2-RC1兼容。 另请参见 。

您需要将二进制文件(字节码.class文件)提供给声纳执行器。 将以下行添加到您的sonar-project.properties中

# Path to the class files
sonar.binaries=build\\classes\\main

如果上面的行不起作用,请检查您的二进制文件的实际路径并将其放在sonar.binaries属性中

  相关解决方案