使用maven和Jenkins的SonarQube 3.7 - Maven会话不会声明顶级项目

时间:2013-09-03 09:23:05

标签: maven jenkins sonarqube

上下文

我目前遇到的问题是sonarqube 3.7由maven通过jenkins运行

项目设置为maven多模块项目,jenkins使用以下参数运行声纳(通过maven):“ - pl”

我已将“声纳”3.6更新为“sonarqube”3.7并将“sonar-maven-plugin”更新为3.7

问题

自更新以来,我在jenkins(1.529)中看到以下错误:

[ERROR] Failed to execute goal org.codehaus.sonar:sonar-maven-plugin:3.7:sonar (default-cli) on project xxxxx: Execution default-cli of goal org.codehaus.sonar:sonar-maven-plugin:3.7:sonar failed: Unable to execute Sonar: Maven session does not declare a top level project -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.sonar:sonar-maven-plugin:3.7:sonar (default-cli) on project xxxxx: Execution default-cli of goal org.codehaus.sonar:sonar-maven-plugin:3.7:sonar failed: Unable to execute Sonar
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.codehaus.sonar:sonar-maven-plugin:3.7:sonar failed: Unable to execute Sonar
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
    at org.sonar.runner.api.Runner.execute(Runner.java:90)
    at org.sonar.maven.SonarMojo.execute(SonarMojo.java:172)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    ... 20 more
Caused by: java.lang.IllegalStateException: Maven session does not declare a top level project
    at org.sonar.plugins.maven.MavenProjectBootstrapper.bootstrap(MavenProjectBootstrapper.java:53)
    at org.sonar.batch.scan.ProjectScanContainer.projectBootstrap(ProjectScanContainer.java:104)
    at org.sonar.batch.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:82)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:86)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:73)
    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57)
    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:82)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:88)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:73)
    at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:156)
    at org.sonar.batch.bootstrap.BootstrapContainer.doAfterStart(BootstrapContainer.java:144)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:88)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:73)
    at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:92)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:74)
    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
    ... 28 more

预期行为

声纳应检查代码与之前版本

一样

替代解决方案

如果我不使用-pl param(仅当我在sonarqube中删除项目时才有效)

但我仍然只想在特定模块上运行声纳。

5 个答案:

答案 0 :(得分:5)

您正在遇到很多我们沉重的SonarQube用户定期找到的内容:任何调用SonarQube 的非名义技术将在某些最终升级期间中断。我们在工作中已经习惯了,我们只是简单地将升级问题烘焙到SonarQube升级的成本中。

我不怀疑-pl过去是否有效。但是,随着SonarQube继续使用许多语言,它将成为仅限Java和Maven的连续检查工具。

SonarQube在您将其作为简单mvn sonar:sonar调用时最开心。您应该在多模块父POM中指定其他SonarQube配置,因为这是现在和将来修改配置的唯一保证方式。

如果您只想针对一个模块运行SonarQube,请将sonar.includedModules设置为仅包含多模块父模块和目标模块。因此,如果您的多模块父项<artifactId> foo-parent 且您所需的模块是 foo-module ,则需要在 foo-中设置以下属性 - 父母的POM:

sonar.includedModules=foo-parent,foo-module

答案 1 :(得分:1)

SonarQube不支持Maven'-pl'选项,请参阅http://jira.codehaus.org/browse/SONAR-1742

答案 2 :(得分:1)

sonar.includedModules自4.3以来已弃用

https://docs.sonarqube.org/display/SONARQUBE53/Release+4.3+Upgrade+Notes

  

不推荐使用sonar.skippedModules和sonar.includedModules属性。它们应该由标准Maven高级反应堆选项取代。例如,假设您有以下多模块项目:

 org.mycompany:my-project
     - moduleA (org.mycompany:module-A)
     - moduleB (org.mycompany:module-B)
     - moduleC (org.mycompany:module-C)

然后

mvn sonar:sonar -Dsonar.skippedModules=module-B 
  

应该替换(自Maven 3.2.1起)

mvn sonar:sonar -pl !moduleB

答案 3 :(得分:1)

当我尝试通过诸如:-sonar:sonar -pl moduleA之类的命令在其父模块中运行声纳时,我遇到了同样的问题,因此我尝试了此操作并与:-{{1} }。这将在多模块Maven项目和我们指定的“。”中仅构建一个特定项目。它将建立父pom来解决该问题。

答案 4 :(得分:0)

我知道这是一个有点老问题,但是在这种使用-pl选项的情况下帮助我的是使用相反的逻辑。您不应该传递要执行分析的模块,而应该传递您不想分析的模块。例如,如果您有4个模块并且只想分析第三个模块,那么您-pl看起来像这样:

-pl !module1,!module2,!module4