2013-07-06 67 views
0

我有聲納插件的父母pom文件,我希望聲納分別分析每個兒童模塊。這是在父POM我聲納定義:如何運行聲納分別分析每個兒童模塊

  <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>sonar-maven-plugin</artifactId> 
      <version>1.0</version> 
      <executions> 
       <execution> 
        <id>running-sonar</id> 
        <goals> 
         <goal>sonar</goal> 
        </goals> 
        <phase>install</phase> 
       </execution> 
      </executions> 
     </plugin> 

,並與繼承父POM模塊30多個模塊,並且構建所有模塊一起另一個POM。當我想MVN潤潔在構建POM安裝,我得到這個異常:

[INFO] Can not execute Sonar 

Embedded error: Not a root project: [email protected] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Trace 
org.apache.maven.lifecycle.LifecycleExecutionException: Can not execute Sonar 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) 
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) 
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) 
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) 
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375) 
Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar 
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:103) 
    at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:79) 
    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:88) 
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) 
    ... 17 more 
Caused by: java.lang.IllegalArgumentException: Not a root project: [email protected] 
    at org.sonar.api.batch.bootstrap.ProjectReactor.<init>(ProjectReactor.java:36) 
    at org.sonar.maven.SonarMojo.execute(SonarMojo.java:138) 
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
    at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98) 
    ... 21 more 

回答

0

爲了運行聲納和聚集所有從父項目的結果,加上inherited=false標誌父POM:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>sonar-maven-plugin</artifactId> 
    <version>1.0</version> 
    <inherited>false</inherited> 
    <executions> 
    .... 

否則,每個模塊會嘗試運行聲納執行作爲父級和插件的投訴。

在需要的情況下,您仍然可以從模塊運行mvn sonar:sonar來分析只有其代碼庫,而不會彙總其他模塊的結果。然而,最新版本的Sonar已準備好處理多模塊項目,從Web界面瀏覽每個模塊。

+0

我使用了這個標籤,但我仍然有問題 – Pooya

+0

我已經在多模塊項目中用sonar-maven-plugin-1.0和Maven 3.x測試了Maven 2.x和sonar-maven-plugin-2.0,並且兩者都很好。你能否證實在任何子模塊中沒有聲納插件聲明?它應該只在父pom中聲明,因此每個孩子都會繼承配置,但不會運行插件。 – edrabc