Error while generating sonarqube analysis from ant build

1,379 views
Skip to first unread message

swethap...@gmail.com

unread,
Jul 27, 2017, 5:50:30 AM7/27/17
to SonarQube
Hi,

I got the below error while generating analysis from SonarQube for ant build

D:\new_ant>ant sonar
Buildfile: D:\new_ant\build.xml

sonar:
[sonar:sonar] Apache Ant(TM) version 1.10.1 compiled on February 2 2017
[sonar:sonar] Sonar Ant Task version: 2.1
[sonar:sonar] Loaded from: file:/D:/apache-ant-1.10.1-bin/apache-ant-1.10.1/lib/sonar-ant-task-2.1.jar
[sonar:sonar] INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
[sonar:sonar] INFO: Work directory: D:\new_ant\.sonar
[sonar:sonar] INFO: Sonar Server 5.6.6

BUILD FAILED
D:\new_ant\build.xml:46: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:79)
        at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:63)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:57)
        at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
        at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:71)
        at org.sonar.runner.api.Runner.execute(Runner.java:89)
        at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:53)
        at org.sonar.ant.SonarTask.execute(SonarTask.java:48)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        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:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
        at org.apache.tools.ant.Main.runBuild(Main.java:857)
        at org.apache.tools.ant.Main.startAnt(Main.java:236)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
Caused by: java.lang.NoSuchMethodError: org.sonar.batch.bootstrapper.Batch$Builder.setProjectReactor(Lorg/sonar/api/batch/bootstrap/ProjectReactor;)Lorg/sonar/batch/bootstrapper/Batch$Builder;
        at org.sonar.runner.batch.IsolatedLauncher.createBatch(IsolatedLauncher.java:67)
        at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:75)
        ... 25 more

My ant build.xml
<project name="HelloWorld" basedir="." default="all" xmlns:sonar="antlib:org.sonar.ant">

    <property name="src.dir"     value="src"/>

    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>

    <property name="main-class"  value="oata.HelloWorld"/>

<property name="sonar.host.url" value="https://localhost:9000" />

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
<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" />
    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    </target>
<target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
    </target>

    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>
<target name="sonar">
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="D:\sonarqube-5.6.6\sonarqube-5.6.6\lib\sonar-application-5.6.6.jar" />
</taskdef>
<sonar:sonar />
</target>

</project>

Please suggest me what went wrong and modificatons needs to do.

Thanks
Swetha


G. Ann Campbell

unread,
Jul 27, 2017, 9:06:22 AM7/27/17
to SonarQube
Hi,

The current version of the Ant task is 2.5. Could you upgrade and try again?


Ann

swethap...@gmail.com

unread,
Jul 31, 2017, 2:16:33 AM7/31/17
to SonarQube
Hi Ann,

Thanks for the information. I upgraded ant task it to Ant task is 2.5 and tried. Now,getting the below error.

Setting ro project property: ant.file -> D:\new_ant\build.xml
Setting ro project property: ant.file.type -> file
Setting ro project property: ant.project.invoked-targets -> sonar:sonar
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile D:\new_ant\build.xml with URI = file:/D:/new_ant/build.xml
Setting ro project property: ant.project.name -> HelloWorld
Adding reference: HelloWorld
Setting ro project property: ant.project.default-target -> main
Setting ro project property: ant.file.HelloWorld -> D:\new_ant\build.xml
Setting ro project property: ant.file.type.HelloWorld -> file
Project base dir set to: D:\new_ant
 +Target:
 +Target: clean
 +Target: compile
 +Target: jar
 +Target: run
 +Target: clean-build
 +Target: main
 +Target: sonar
Adding reference: ant.LocalProperties
parsing buildfile jar:file:/D:/apache-ant-1.10.1-bin/apache-ant-1.10.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/D:/apache-ant-1.10.1-bin/apache-ant-1.10.1/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Setting project property: src.dir -> src
Setting project property: build.dir -> build
Setting project property: classes.dir -> build/classes
Setting project property: jar.dir -> build/jar
Setting project property: main-class -> oata.HelloWorld
Override ignored for property "sonar.host.url"
Setting project property: sonar.projectKey -> org.sonarqube:sonarqube-scanner-ant
Setting project property: sonar.projectName -> Example of SonarQube Scanner for Ant Usage
Setting project property: sonar.projectVersion -> 1.0
Setting project property: sonar.sources -> src
Setting project property: sonar.java.binaries -> build
Setting project property: sonar.java.libraries -> lib/*.jar
Setting ro project property: ant.project.invoked-targets -> sonar:sonar
Attempting to create object of type org.apache.tools.ant.helper.DefaultExecutor
Adding reference: ant.executor

BUILD FAILED
Target "sonar:sonar" does not exist in the project "HelloWorld".
        at org.apache.tools.ant.Project.tsort(Project.java:1929)
        at org.apache.tools.ant.Project.topoSort(Project.java:1837)
        at org.apache.tools.ant.Project.topoSort(Project.java:1800)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
        at org.apache.tools.ant.Main.runBuild(Main.java:857)
        at org.apache.tools.ant.Main.startAnt(Main.java:236)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)

Please find my Build.xml file configuration:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="main" basedir="." xmlns:sonar="antlib:org.sonar.ant">
<classpath path="D:\sonarqube-5.6.6\sonarqube-5.6.6\lib\sonarqube-ant-task-2.5.jar" />
</taskdef>

<sonar:sonar />
</target>

</project>

Thanks,
Swetha

G. Ann Campbell

unread,
Jul 31, 2017, 7:55:57 AM7/31/17
to swethap...@gmail.com, SonarQube
Hi Swetha,

The error is pretty straightforward:
Target "sonar:sonar" does not exist in the project "HelloWorld".

The target in your Ant file is "sonar".


Ann 



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/mMScc7VKx8k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/af985203-d26b-48a3-9fb8-e014b10c1f8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

swethap...@gmail.com

unread,
Aug 1, 2017, 2:05:26 AM8/1/17
to SonarQube, swethap...@gmail.com
Hi Ann,

I have defined the sonar:sonar in the build.xml which is located at the end of the file.

Thanks,
Swetha
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

swethap...@gmail.com

unread,
Aug 1, 2017, 3:42:14 AM8/1/17
to SonarQube, swethap...@gmail.com
Hi Ann,

I have changed the target in build.xml and able to compile the build successfully but not able to lanch the analysis
Please suggest me how to access analysis.

Buildfile: D:\new_ant\build.xml

sonar:
Trying to override old definition of task antlib:org.sonar.ant:sonar

BUILD SUCCESSFUL
Total time: 0 seconds

Build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="main" basedir="." xmlns:sonar="antlib:org.sonar.ant">
    <property name="src.dir"     value="src"/>
    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>
    <property name="main-class"  value="oata.HelloWorld"/>
<property name="sonar.host.url" value="localhost:9000/" />

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>
<property name="sonar.projectKey" value="com.sample.proj" />
<property name="sonar.projectName" value="Example of SonarQube Scanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="src" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.projectBaseDir" value="D:\new_ant" />
<property name="sonar.java.libraries" value="lib/*.jar" />
    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    </target>
<target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
    </target>

    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>
<target name="sonar">
<taskdef resource="org/sonar/ant/antlib.xml" uri="antlib:org.sonar.ant" >
<classpath path="D:\sonarqube-ant-task-2.5.jar" />
</taskdef>
 </target>

</project>


Thanks,
Swetha

G. Ann Campbell

unread,
Aug 1, 2017, 7:25:08 AM8/1/17
to swethap...@gmail.com, SonarQube
Hi Swetha,

This bears repeating:

Hi Swetha,

The error is pretty straightforward:
Target "sonar:sonar" does not exist in the project "HelloWorld".

The target in your Ant file is "sonar".

And by that, I literally mean that the name you gave to the relevant target is "sonar". As in: 

 <target name="sonar">

Which means you need to run: ant sonar
not: ant sonar:sonar

I would, however suggest this small modification to your build:

<target name="sonar" depends="compile">

Or perhaps this instead:
<target name="jar" depends="compile, sonar">


 Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/be38f121-257b-4d78-b604-bbf6789ef5e6%40googlegroups.com.

swethap...@gmail.com

unread,
Aug 2, 2017, 2:15:17 AM8/2/17
to SonarQube, swethap...@gmail.com
Hi Ann,

Thank you for the support and information. Its working now.

Best regards,
Swetha
Reply all
Reply to author
Forward
0 new messages