1

Maven 以外のプロジェクトを持っていますが、Sonar を使用してコード分析を 1 回行う必要があります。だから私はpom.xml素晴らしい作品を作成しました。srcこのpomファイルを使用して、ディレクトリの下にあるすべてのファイルとフォルダーの分析を確認します。

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my.group.id</groupId>
    <artifactId>arifactId</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <name>MyApplication</name>
    <build>
        <sourceDirectory>src</sourceDirectory>
    </build>

    <properties>
        <sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
    </properties>
</project>

しかし、1 つのディレクトリとそのすべてのサブディレクトリを除外したいと考えています。と の 2 つのディレクトリがsrc/fr/ありsrc/com/ます。src/fr/私は持って除外したいだけですsrc/com/。変化

<sourceDirectory>src</sourceDirectory>

<sourceDirectory>src/fr</sourceDirectory>

次のエラーが表示されます。

Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar 
(default-cli) on project arifactId: Can not execute Sonar: Sonar is 
unable to analyze file : '/Users/tim/workspace/src/fr/xxx/dao/TestClass.java': 
The source directory does not correspond to the package declaration fr.xxx.dao
4

1 に答える 1

2

通常、それが私たちに言ったように、Javaファイルで宣言されたがディレクトリ構造と一致しないThe source directory does not correspond to the package declaration場合、エラーです。package

package my.test.java;
public class MyTest {}

The directory should be my/test/java/MyTest.java, 
please note the src is treated as a sourceDirectory.

あなたの場合、sourceDirectoryからsrcsrc/frその意味に変更しました

package fr.xxx.dao;
public class TestClass{}

The directory is xxx/dao/TestClass.java, 
please note the src/fr is treated as a sourceDirectory. Then the fr is ignored.

通常、Sonar 分析から somes パッケージを除外したい場合は、各品質 maven プラグイン ( 、 、 など) でそれらを設定するだけで簡単に実行findbugsできPMDますcobertura

とにかく、ソナーは各プロジェクトの構成も提供します。次の手順を使用して設定できます。 -

注: 私は Sonar バージョン 3.5 を使用しています。別のバージョンを使用している場合は、メニューが異なる場合があります。

  1. ソナーの Web サイトにアクセスします。https://myhost/sonar
  2. ダッシュボードから選択してプロジェクトに移動します。
  3. 右上にConfigurationメニューが表示されます。それをクリックして、 を選択しますSettings
  4. Settingsページで、メニューを選択しますExclusions
  5. Exclusionsワイルドカードも使用できる除外モジュールを簡単に設定できます。(ページの下部に例が表示されます。)
  6. あなたのケースの例では、除外はfr/**. (フォルダ fr の下のすべてを除外します)。

次のリンクを参照してください: -

  1. プロジェクト管理
  2. ファイル
  3. 解析パラメータ

これが役立つことを願っています。

于 2013-03-25T01:27:03.770 に答える