为什么 Sonar 设计视图没有显示我的项目的任何依赖项?

发布于 2024-11-05 21:37:36 字数 2701 浏览 0 评论 0原文

我已经针对使用 Ant 构建的大型 Java 项目成功设置了 Sonar。我终于连接了 JUnit 测试结果和 Cobertura 代码覆盖率报告。

我现在在设计视图中看到了所有包,但任何包或类之间都没有依赖关系的值(请参见下面的示例)。

No dependency

有谁知道我在这里错过了什么?

更新

查看 Sonar Ant 任务的输出,我还注意到,对于一个相当大且复杂的项目,包设计任务完成得非常快。从 Ant 输出来看:

[sonar:sonar] [INFO]  Package design analysis...
[sonar:sonar] [INFO]  Package design analysis done: 66 ms

Ant 任务如下:

<target name="sonar" depends="collate-xml-reports">
    <sonar:sonar workDir="src/build/sonarTemp" key="myProjectKeyWhichHasBeenChangedToHideMyClient" version="1.0" xmlns:sonar="antlib:org.sonar.ant">

        <!-- source directories (required) -->
        <sources>
            <path location="src/common/src" />
            <path location="src/commonWidgets/src" />
            <path location="src/compositionWidget/src" />
            <path location="src/nativeLib/src" />
            <path location="src/services/src" />
        </sources>

        <!-- list of properties (optional) -->
        <property key="sonar.projectName" value="RPS Nightly" />
        <property key="sonar.dynamicAnalysis" value="reuseReports" />
        <property key="sonar.surefire.reportsPath" value="src/reports/junit" />
        <property key="sonar.cobertura.reportPath" value="src/reports/cobertura/coverage.xml" />

        <!-- test source directories (optional) -->
        <tests>
            <path location="src/common/test" />
            <path location="src/commonWidgets/test" />
            <path location="src/compositionWidget/test" />
            <path location="src/services/test" />
        </tests>

        <!-- binaries directories, which contain for example the compiled Java bytecode (optional) -->
        <binaries>
            <path location="src/common/build" />
            <path location="src/commonWidgets/build" />
            <path location="src/compositionWidget/build" />
            <path location="src/services/build" />
        </binaries>

        <!-- path to libraries (optional). These libraries are for example used by the Java Findbugs plugin -->
        <libraries>
            <path location="src/common/lib/**/" />
            <path location="src/commonWidgets/lib/**/" />
            <path location="src/compositionWidget/lib/**/" />
            <path location="src/services/lib/" />
        </libraries>
    </sonar:sonar>
</target>

I've successfully set up Sonar against a large Java project that is built using Ant. I've finally hooked up the JUnit test results and the Cobertura code coverage report.

I now see all the packages in the design view but there are no values for dependencies between any of the packages or classes (see example below).

No dependencies

Does anyone have any idea what I have missed here?

UPDATE

Looking at the output of the Sonar Ant task I also notice that the package design task is completing very quickly for what is a fairly large and complicated project. From the Ant output:

[sonar:sonar] [INFO]  Package design analysis...
[sonar:sonar] [INFO]  Package design analysis done: 66 ms

The Ant task is as follows:

<target name="sonar" depends="collate-xml-reports">
    <sonar:sonar workDir="src/build/sonarTemp" key="myProjectKeyWhichHasBeenChangedToHideMyClient" version="1.0" xmlns:sonar="antlib:org.sonar.ant">

        <!-- source directories (required) -->
        <sources>
            <path location="src/common/src" />
            <path location="src/commonWidgets/src" />
            <path location="src/compositionWidget/src" />
            <path location="src/nativeLib/src" />
            <path location="src/services/src" />
        </sources>

        <!-- list of properties (optional) -->
        <property key="sonar.projectName" value="RPS Nightly" />
        <property key="sonar.dynamicAnalysis" value="reuseReports" />
        <property key="sonar.surefire.reportsPath" value="src/reports/junit" />
        <property key="sonar.cobertura.reportPath" value="src/reports/cobertura/coverage.xml" />

        <!-- test source directories (optional) -->
        <tests>
            <path location="src/common/test" />
            <path location="src/commonWidgets/test" />
            <path location="src/compositionWidget/test" />
            <path location="src/services/test" />
        </tests>

        <!-- binaries directories, which contain for example the compiled Java bytecode (optional) -->
        <binaries>
            <path location="src/common/build" />
            <path location="src/commonWidgets/build" />
            <path location="src/compositionWidget/build" />
            <path location="src/services/build" />
        </binaries>

        <!-- path to libraries (optional). These libraries are for example used by the Java Findbugs plugin -->
        <libraries>
            <path location="src/common/lib/**/" />
            <path location="src/commonWidgets/lib/**/" />
            <path location="src/compositionWidget/lib/**/" />
            <path location="src/services/lib/" />
        </libraries>
    </sonar:sonar>
</target>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-11-12 21:37:37

作为一名 Java 高手,事实证明这是我的一个误解。二进制文件目录位置需要指向已编译的 Java 字节码的根文件夹,但我将其指向 jar 文件位置。在这种情况下,字节码被写入 build/classes 文件夹,因此我需要将我的 ant 目标(如问题中所示)从: 修改

    <binaries>
        <path location="src/common/build" />
        <path location="src/commonWidgets/build" />
        <path location="src/compositionWidget/build" />
        <path location="src/services/build" />
    </binaries>

为:

    <binaries>
        <path location="src/common/build/classes" />
        <path location="src/commonWidgets/build/classes" />
        <path location="src/compositionWidget/build/classes" />
        <path location="src/services/build/classes" />
    </binaries>

这解决了问题,并且设计视图现在已正确填充。

Being a Java n00b it turns out that this was a misunderstanding on my part. The binaries directory locations need to point to the root folder of the compiled Java bytecode but I was pointing it to the jar file location. In this case the bytecode is written to the build/classes folder so I needed to modify my ant target (shown in the question) from:

    <binaries>
        <path location="src/common/build" />
        <path location="src/commonWidgets/build" />
        <path location="src/compositionWidget/build" />
        <path location="src/services/build" />
    </binaries>

To:

    <binaries>
        <path location="src/common/build/classes" />
        <path location="src/commonWidgets/build/classes" />
        <path location="src/compositionWidget/build/classes" />
        <path location="src/services/build/classes" />
    </binaries>

This fixed the problem and the design view is now correctly populated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文