Ant with sonarqube

Hi,

  • How to scan ant projects with sonar
  • I got error while running ant sonar commond
  • error : Fail to download libraries from server
  • Please do the needful

Hi Madhumohan,

Please share the must-have information when posting any question in the community, otherwise there is little way anyone can help you:

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

When you say:

Please keep in mind this is a community of SonarQube users who voluntarily help each other, and therefore, there is no obligation for anyone to do anything.

Best regards,
Daniel

Hi Daniel,

I got report on sonar server with code of build.xml file

<property name="ANT_CLASSPATH" value="lib" />
<property name="sonar.host.url" value="http://localhost:9000"  />
<property name="sonar.login" value="abcd" />
<property name="sonar.password" value="abcd" />
<property name="sonar.projectKey" value="sonarbuild" />
<property name="sonar.projectName" value="sonarbuild" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="." />
<property name="sonar.java.binaries" value="dist" />

	<property name="sonar.sourceEncoding" value="ISO-8859-1" />

<!-- - - - - - - - - - - - - - - - - - 
      target: name                      
     - - - - - - - - - - - - - - - - - -->
<target name="sonar">
	<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        	<classpath path="sonar-ant-task-2.3.jar" />
        </taskdef>
	    <sonar:sonar />
</target>

But, I’m getting error when i mention the remote server instead of localhost
Please find the error details
build.xml:26: java.lang.IllegalStateException: Fail to download libraries from server

Sonarqube : Version 8.4.2

Madhumohan, I will need the full log of the analysis in debug mode in order to be able to help.

Best regards,
Daniel

Hi Daniel,
Please find the logs

D:\Dev\Portal\liferay-plugins-sdk-6.1.1\portlets\BeamPromotionalNDownloads-portlet\build.xml:28: java.lang.IllegalStateException: Fail to download libraries from server
at org.sonar.runner.impl.Jars.dowloadFiles(Jars.java:78)
at org.sonar.runner.impl.Jars.download(Jars.java:57)
at org.sonar.runner.impl.JarDownloader.download(JarDownloader.java:46)
at org.sonar.runner.impl.JarDownloader.checkVersionAndDownload(JarDownloader.java:37)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:71)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:51)
at org.sonar.ant.SonarTask.execute(SonarTask.java:46)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
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:352)
at org.apache.tools.ant.Target.execute(Target.java:437)
at org.apache.tools.ant.Target.performTasks(Target.java:458)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1406)
at org.apache.tools.ant.Project.executeTarget(Project.java:1377)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1261)
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:112)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.sonar.runner.impl.Jars.dowloadFiles(Jars.java:72)
… 27 more

Total time: 1 second

Hi Madhumohan,

These are unfortunately not the full logs: I would need the full logs from the line in which you launch the SonarScanner. Also, please can you tell what is the SonarScanner version you are using?

Thanks, regards,
Daniel

Hi Daniel,

please find the logs and SonarScanner version : sonar-scanner-4.4.0.2170-linux

D:\Dev\Portal\liferay-plugins-sdk-6.1.1\portlets\BeamPromotionalNDownloads-portlet>ant sonar
Buildfile: D:\Dev\Portal\liferay-plugins-sdk-6.1.1\portlets\BeamPromotionalNDownloads-portlet\build.xml

sonar:
[sonar:sonar] Apache Ant™ version 1.9.15 compiled on May 10 2020
[sonar:sonar] SonarQube Ant Task version: 2.3
[sonar:sonar] Loaded from: file:/D:/devopssw/apache-ant-1.9.15/lib/sonar-ant-task-2.3.jar
[sonar:sonar] INFO: Default locale: “en_GB”, source code encoding: “ISO-8859-1”
[sonar:sonar] INFO: Work directory: D:\Dev\Portal\liferay-plugins-sdk-6.1.1\portlets\BeamPromotionalNDownloads-portlet.sonar
[sonar:sonar] INFO: SonarQube Server 8.4.2.36762

BUILD FAILED
D:\Dev\Portal\liferay-plugins-sdk-6.1.1\portlets\BeamPromotionalNDownloads-portlet\build.xml:28: java.lang.IllegalStateException: Fail to download libraries from server
at org.sonar.runner.impl.Jars.dowloadFiles(Jars.java:78)
at org.sonar.runner.impl.Jars.download(Jars.java:57)
at org.sonar.runner.impl.JarDownloader.download(JarDownloader.java:46)
at org.sonar.runner.impl.JarDownloader.checkVersionAndDownload(JarDownloader.java:37)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:71)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:51)
at org.sonar.ant.SonarTask.execute(SonarTask.java:46)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
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:352)
at org.apache.tools.ant.Target.execute(Target.java:437)
at org.apache.tools.ant.Target.performTasks(Target.java:458)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1406)
at org.apache.tools.ant.Project.executeTarget(Project.java:1377)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1261)
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:112)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.sonar.runner.impl.Jars.dowloadFiles(Jars.java:72)
… 27 more

Total time: 9 seconds

Hi Mahumohan,

Please note that you seem to be using SonarScanner for Ant and therefore, the “sonar-scanner-4.4.0.2170-linux” version that you shared with me is irrelevant.

The problem is potentially due to your SonarScanner for Ant version (2.3) which is really old. You will have to upgrade to SonarScanner for Ant 2.7 and try scanning again.

Cheers,
Daniel

HI Daniel,

Thanks for your support :+1:
It’s working now

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.