0

我正在使用 Sonar 3.5.1、Java 1.6.0_26 和 Apache Ant 1.9.0;并下载目录下的插件sonar-ant-task-2.1.jar apache-ant-1.9.0/lib/

当我运行 ant sonar 任务时,我遇到了错误:

build.xml:115:声纳:声纳不支持“关键”属性

这个问题真的让我疯狂了一个星期。你能告诉我问题是什么吗?

<!-- ========= Define Sonar target ========= -->
<property name="sonar.projectKey" value="org.codehaus.sonar:${eid}-test" />
<property name="sonar.projectName" value="${eid}-test" />
<property name="sonar.sources" value="${src.dir}" />
<property name="sonar.language" value="c++" />
<property name="sonar.binaries" value="${classes.dir}" />
<property name="sonar.surefire.reportsPath" value="${reports.junit.xml.dir}" />   
<property name="sonar.cxx.cppcheck.reportPath" value="${reports.dir}/cppcheck-report.xml" />
<property name="sonar.cxx.gcovr.reportPath" value="${reports.dir}/gcovr-report.xml" />
<property name="sonar.cxx.xunit.reportPath" value="${reports.dir}/gtest-report.xml" />

<!-- The following properties are required to use JaCoCo: -->
<!-- 1. Tells Sonar to run the unit tests -->
<!--
<property name="sonar.dynamicAnalysis" value="true" />
-->
<!-- 2. Tells Sonar which "tests" targets to run -->

<!-- 3. Tells Sonar to use JaCoCo as the code coverage engine -->
<!--
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
-->

<target name="sonar" depends="cppcheck-report">
    <sonar:sonar key="org.codehaus.sonar:${eid}-test" version="1.0" xmlns:sonar="antlib:org.sonar.ant" />
</target>

<!-- ========= The main target "all" ========= -->
<!-- Note that depending on the "run-tests" target is not mandatory, as Sonar Ant task will launch it thanks to the "sonar.jacoco.antTargets" property -->
<!-- However, note that compiling is required before running the Sonar Ant task -->
<target name="all" depends="clean,compile,cppcheck-report" />
4

2 回答 2

4

这是 Sonar Ant 任务文档的链接:

http://docs.codehaus.org/display/SONAR/Analyzing+with+SonarQube+Ant+Task#AnalyzingwithSonarQubeAntTask-SimpleProject

您将看到项目密钥应在sonar.projectKey属性的帮助下定义。

于 2013-05-25T16:54:54.207 回答
0

一个多月以来我一直在寻找同样的问题,终于得到了解决方案。我遵循了 SonarQube 在线文档以及多个线程提供的许多在线帮助和说明,但最终感到更加沮丧。

然后我尝试了 sonar-ant-task 1.5 并按照命令中具有keyversion属性的 build.xmlsonar:sonar并且它工作。然后我用 sonar-ant-task-2.1(最新可用)尝试了这个命令,它也能正常工作。

那么这是我的配置

  • JDK:1.6.0_12(32 位)
  • 声纳服务器:3.7.2
  • 声纳蚂蚁任务运行器:sonar-ant-task-2.1.jar
  • 阿帕奇蚂蚁:1.8.4

以下是我的 ant 的 build.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<project basedir="." default="sonar-runner" name="vApplicationUtilities" xmlns:sonar="antlib:org.sonar.ant">

<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.5"/>
<property name="source" value="1.5"/>

<!-- Define the SonarQube properties -->
<property name="sonar.host.url" value="http://my-sonar-server:9000/sonar" />
<property name="sonar.jdbc.url" value="jdbc:jtds:sqlserver://my-sql-server-host/sonar;SelectMethod=Cursor" />
<property name="sonar.jdbc.username" value="username" />
<property name="sonar.jdbc.password" value="password" />
<property name="sonar.projectKey" value="my-project-key" />
<property name="sonar.projectName" value="vApplicationUtilities" />
<property name="sonar.projectVersion" value="4.0.0020" />
<property name="sonar.language" value="java" />
<property name="sonar.profile" value="My Analyzer" />
<property name="sonar.sources" value="src" />
<property name="sonar.sourceEncoding" value="UTF-8" />

<path id="vApplicationUtilities.classpath">
    <pathelement location="build/classes"/>
    <path refid="EAR Libraries.libraryclasspath"/>
    <path refid="JBoss 5.0 Runtime [JBoss 5.0 Runtime].libraryclasspath"/>
</path>

<target name="init">
    <mkdir dir="build/classes"/>
    <copy includeemptydirs="false" todir="build/classes">
        <fileset dir="src">
            <exclude name="**/*.launch"/>
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>

<target name="clean">
    <delete dir="build/classes"/>
    <delete dir=".sonar"/>
</target>

<target depends="clean" name="cleanall"/>

<target depends="cleanall,build-project" name="build">
    <echo message="Creating dist/vApplicationUtilities.jar"/>
    <jar destfile="dist/vApplicationUtilities.jar" basedir="build/classes" manifest="build/classes/META-INF/MANIFEST.MF"/>
</target>

<target depends="init" name="build-project">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac includeantruntime="false" debug="true" debuglevel="${debuglevel}" destdir="build/classes" source="${source}" target="${target}">
        <src path="src"/>
        <classpath refid="vApplicationUtilities.classpath"/>
    </javac>
</target>

<target depends="build" name="sonar-runner">
    <!-- run sonar for this project -->
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <!-- Update the following line, or put the "sonar-ant-task-*.jar" file 
            in your "$HOME/.ant/lib" folder -->
        <classpath path="${lib-dist}/sonar/sonar-ant-task-2.1.jar" />
    </taskdef>
    <!-- Execute Sonar -->
    <sonar:sonar key="${sonar.projectKey}" version="${sonar.projectVersion}" />
</target>

</project>

此外,您访问了一些在线帮助,讨论了最新版本的 sonar ant 任务 (2.x) 不需要 sonar runner 任务中的keyandversion属性。真是废话,我已经浪费了很多时间在那个错过领先的指导方针上。您确实需要这两个属性才能使声纳任务运行。

希望这会照亮你的一天。谢谢

于 2013-11-12T12:36:35.553 回答