我正在尝试构建一个Android java 项目分支:feature-Fprototype_app
我收到此错误:
[INFO] [13:38:36.470] Base dir: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile
[INFO] [13:38:36.470] Working dir: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/target/sonar
[INFO] [13:38:36.470] Source dirs: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src
[INFO] [13:38:36.470] Binary dirs: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/target/classes
[INFO] [13:38:36.470] Source encoding: UTF-8, default locale: en_US
[INFO] [13:38:36.489] Sensor JavaSourceImporter...
[INFO] [13:38:36.710] Sensor JavaSourceImporter done: 221 ms
[INFO] [13:38:36.710] Sensor JavaSquidSensor...
[INFO] [13:38:36.800] Java AST scan...
[ERROR] Sonar is unable to analyze file : '/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src/main/java/com/simpragma/apps/textify/db/BookmarkDao.java'
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] -------------------
[INFO] Total time:14.245s
[INFO] Finished at: Thu Oct 17 13:38:36 GMT+05:30 2013
[INFO] Final Memory: 14M/102M
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project Textify: Can not execute SonarQube analysis: Sonar is unable to analyze file :
**'/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src/main/java/com/simpragma/apps/textify/db/BookmarkDao.java': The source directory does not correspond to the package declaration** com.simpragma.apps.textify.db ->
[Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project Textify: Can not execute SonarQube analysis
在詹金斯配置后构建操作中,我试图sonar.sources
在附加属性框中设置(因为当我搜索错误时,人们建议为源设置正确的路径)。我尝试了许多组合,例如:
-Dsonar.sources=mobile/src/main/java
-Dsonar.sources=/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src/main/java
-Dsonar.sources=/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile
仍然是同样的错误。我究竟做错了什么 ?
好的,让我清理一下我造成的混乱。首先,它是一个 android maven 项目。包结构是 com.xyz.abc,源根目录是 src/main/java。在 pom.xml 中,sourceDirectory属性最初设置为指向src。看来maven对源码的根没有任何问题,它正在编译项目。然后,我为这个项目设置了 jenkins 和 sonar。我使用 Jenkins 的Post-build Action对我的项目进行声纳分析。这里的问题是“使用 Maven 运行分析时,某些 SonarQube 属性总是被忽略,因为 SonarQube 在内部从 POM 提供它们” - SONAR-4536。其中一个属性是sonar.sources. 因此,当我在 Jenkins 设置中尝试使用 -Dsonar.sources 时,它不起作用。后来我修改了我的 pom 以指向 src/main/java 这导致通过 jenkins post-build 操作成功分析。
我希望我已经澄清了。