如何将maven项目与SonarQube5.4集成?

时间:2016-04-20 10:20:21

标签: maven sonarqube maven-3 sonarqube-scan sonar-maven-plugin

我想将我的maven java应用程序与SonarQube5.4集成。

使用maven3.3.3和MySQL5.7.12

SonarQube已成功安装并正在运行。

如果我在命令提示符中转到我的项目路径并运行命令mvn sonar:sonar,我收到以下错误

[WARNING] Failed to retrieve plugin descriptor for org.codehaus.sonar:sonar-maven-plugin:2.4: 
Plugin org.codehaus.sonar:sonar-maven-plugin:2.4 or one of its dependencies could not be resolved: 
Failed to read artifact descriptor for org.codehaus.sonar:sonar-maven-plugin:jar:2.4
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/sonar-maven-plugin/maven-metadata.xml
[WARNING] Could not transfer metadata org.codehaus.mojo:sonar-maven-plugin/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org
[ERROR] Error resolving version for plugin 'org.codehaus.mojo:sonar-maven-plugin' 
from the repositories [local (C:\Users\username\.m2\repository), 
central (https://repo.maven.apache.org/maven2)]: 
Plugin not found in any plugin repository -> [Help 1]

但如果我去我的.m2目录 org / codehaus / mojo / sonar-maven-plugin ,我可以找到maven-metadata.xml。我也可以在 org / codehaus / mojo / sonar-maven-plugin / 2.4 文件夹中找到sonar-maven-plugin-2.4.jar, sonar-maven-plugin-2.4.pom

我很困惑,这些可以在本地存储库中找到,然后尝试下载吗?

帮帮我

请在下面找到我的pom.xml

  <?xml version="1.0"?>

<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.mycompany.server</groupId>
    <version>0.0.1-SNAPSHOT</version>
    <artifactId>MyProject</artifactId>
    <packaging>war</packaging>
    <name>MyProject</name>

    <properties>
        <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
        <!-- External Dependencies versions -->
        <build-helper-maven-plugin.version>1.7</build-helper-maven-plugin.version>
        <hibernate.jpa.version>1.0.1.Final</hibernate.jpa.version>
        <hibernate.validator.version>4.3.1.Final</hibernate.validator.version>
        <hibernate.version>4.2.6.Final</hibernate.version>
        <java.version>1.7</java.version>
        <javax.servlet.jsp.version>2.1</javax.servlet.jsp.version>
        <jaxb.version>2.2.4</jaxb.version>
        <jsp-api.version>2.2</jsp-api.version>
        <jstl.version>1.2</jstl.version>
        <junit.version>4.11</junit.version>
        <log4j.version>1.2.15</log4j.version>
        <slf4j.log4j.version>1.6.1</slf4j.log4j.version>
        <maven.assembly.plugin>2.3</maven.assembly.plugin>
        <maven.clean.plugin>2.5</maven.clean.plugin>
        <maven.compiler.plugin>2.0.2</maven.compiler.plugin>
        <maven.dependency.plugin>2.4</maven.dependency.plugin>
        <maven.deploy.plugin>2.7</maven.deploy.plugin>
        <maven.eclipse.plugin>2.9</maven.eclipse.plugin>
        <maven.exec.plugin>1.2.1</maven.exec.plugin>
        <maven.install.plugin>2.3.1</maven.install.plugin>
        <maven.jar.plugin>2.4</maven.jar.plugin>
        <maven.plugin.plugin>3.1</maven.plugin.plugin>
        <maven.surefire.plugin>2.12</maven.surefire.plugin>
        <maven.tomcat.plugin>2.0-beta-1</maven.tomcat.plugin>
        <maven.version.range>[2.2.1,3.1.0)</maven.version.range>
        <maven.versions.plugin>1.3.1</maven.versions.plugin>
        <maven.war.plugin>2.2</maven.war.plugin>
        <oracle.version>6</oracle.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <servlet-api.version>3.0.1</servlet-api.version>
        <spring.version>4.0.6.RELEASE</spring.version>
        <apache.core.http>4.3.2</apache.core.http>
        <apache.http.client>4.3.4</apache.http.client>
        <json.lib.jdk5>2.4</json.lib.jdk5>
        <signpost.commonhttp4>1.2.1.1</signpost.commonhttp4>
        <signpost.core>1.2.1.1</signpost.core>
        <json.version>20140107</json.version>
        <google.oauth.client>1.15.0-rc</google.oauth.client>
        <org.restlet.org>2.0</org.restlet.org>
        <org.restlet>2.0.8</org.restlet>
    </properties>

    <build>

        <plugins>
            <plugin>
                <groupId>org.codehaus.sonar</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                <version>2.4</version>

            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>

                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>

                <configuration>
                    <warName>MyPoriject</warName>
                    <webappDirectory>${webappDirectory}</webappDirectory>

                    <webResources>

                        <resource>
                            <filtering>true</filtering>
                            <directory>src/main/webapp</directory>

                            <includes>
                                <include>**/*.xml</include>
                            </includes>
                        </resource>
                    </webResources>

                    <archive>

                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>${commons.beanutils.version}</version>

            <exclusions>

                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>${commons.cli.version}</version>

            <exclusions>

                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet-api.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>${jsp-api.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${validation-api.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <version>${commons.exec.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>

            <exclusions>

                <exclusion>
                    <groupId>quartz</groupId>
                    <artifactId>quartz</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${jackson.version}</version>
        </dependency>
            <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>
</project>

1 个答案:

答案 0 :(得分:0)

您是否尝试从本地仓库中移除org / codehaus / mojo / sonar-maven-plugin并再次启动maven?