-1
 <target name="sonar">
            <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
            </taskdef>

            <sonar:sonar />
    </target>

我也设置了 SONAR_HOME 环境变量,但是当我执行“ant sonar”时,我收到以下错误我错过了什么

BUILD FAILED
/root/.jenkins/jobs/Project/workspace/dev/archive/build.xml:108: java.lang.IllegalArgumentException:
The following mandatory information is missing:
- task attribute 'key'
- task attribute 'version'
    at org.sonar.ant.SonarTask.checkMandatoryProperties(SonarTask.java:212)
    at org.sonar.ant.SonarTask.execute(SonarTask.java:190)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:811)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

总时间:0秒

4

2 回答 2

0

您正在尝试使用最新版本的 Ant 任务 (2.0) 的“语法”,但似乎这不是您在类路径中拥有的版本。

于 2012-10-16T09:03:59.027 回答
0

看起来您缺少属于您的 build.xml 文件的强制性 SonarQube 属性值。

文档

<!-- Define the SonarQube global properties (the most usual way is to pass 
these properties via the command line) -->
<property name="sonar.host.url" value="http://localhost:9000" />

...

<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.sonarqube:sonarqube-scanner-ant" />
<property name="sonar.projectName" value="Example of SonarQube Scanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.sources" value="src" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />

或者,您也可以将这些值作为参数传递给 ANT。

ant sonar -Dsonar.projectVersion=1.1
于 2018-05-10T23:34:52.837 回答