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>

并且有超过 30 个模块继承了父 pom 模块,以及另一个将所有模块构建在一起的 pom。当我想在构建 pom 中运行 mvn clean install 时,我得到了这个异常:

[INFO] Can not execute Sonar

Embedded error: Not a root project: org.sonar.api.batch.bootstrap.ProjectDefinition@94347a9e
[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: org.sonar.api.batch.bootstrap.ProjectDefinition@94347a9e
    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
4

1 回答 1

2

为了运行声纳并聚合来自父项目的所有结果,请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 界面浏览每个模块。

于 2013-07-06T17:54:46.647 回答