0

We have a setup where we use SonarQube with Ant and connect to SonarCloud (https://sonarcloud.io). This setup was always working from local developer machine and also from bitbucket pipelines. Since two days, we have been getting below error on local and bitbucket pipelines. Below is the stacktrace:

Project.sonar:
[sonar:sonar] Apache Ant(TM) version 1.10.5 compiled on July 10 2018
[sonar:sonar] SonarQube Ant Task version: 2.5
[sonar:sonar] Loaded from: file:<redacted_path>/sonarqube-ant-task-2.5.jar
[sonar:sonar] User cache: /Users/<user>/.sonar/cache

BUILD FAILED
<redacted_path>/build-sonar.xml:120: java.lang.IllegalStateException: not started
    at org.sonarsource.scanner.api.EmbeddedScanner.checkLauncherExists(EmbeddedScanner.java:244)
    at org.sonarsource.scanner.api.EmbeddedScanner.stop(EmbeddedScanner.java:164)
    at org.sonarsource.scanner.ant.SonarQubeTask.launchAnalysis(SonarQubeTask.java:101)
    at org.sonarsource.scanner.ant.SonarQubeTask.execute(SonarQubeTask.java:81)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
    at org.apache.tools.ant.Task.perform(Task.java:350)
    at org.apache.tools.ant.Target.execute(Target.java:449)
    at org.apache.tools.ant.Target.performTasks(Target.java:470)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1388)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1361)
    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:834)
    at org.apache.tools.ant.Main.startAnt(Main.java:223)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

Below is the command that we use for running sonar:

ant compile Project.sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=<org_name> -Dsonar.login=<token_which_has_all_privs>

We have tried changing the sonar.login token with a new one (thinking that old might have expired) but it didn't work with new one also.

I am not able to find any help anywhere else regarding this error since it does not say much. I see other errors like "WebApp did not start" but that seems to be related to the use case where SonarQube is running on local. But in our case we are connecting to https://sonarcloud.io host. We have also tried with sonar.login and sonar.password and it still fails.

Any help would be appreciated.

Update 1 for mc1arke question Is this sufficient? I can create a new basic build-sonar.xml and provide it but it will only have below content and some properties/variables specific for our environment.

Extract from build-sonar.xml looks as below:

<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
    <classpath>
        <pathelement location="${lib.dir}/sonarqube-ant-task-2.5.jar"/>
    </classpath>
</taskdef>

<target name="Project.sonar">
    <property name="sonar.projectKey" value="ProjectKey" />
    <property name="sonar.projectName" value="ProjectName" />
    <property name="sonar.projectVersion" value="1.0" />
    <property name="sonar.sources" value="${src.dir}" />
    <property name="sonar.binaries" value="${build.dir}" />
    <property name="sonar.java.binaries" value="${build.dir}" />
    <property name="sonar.java.libraries" value="${lib.dir}/*.jar"/>
    <property name="sonar.java.test.libraries" value="${lib.dir}/*.jar"/>
    <property name="sonar.java.source" value="1.8" />
    <property name="sonar.exclusions" value="<some modules>"/>
    <property name="sonar.jacoco.reportPath" value="${junit.reports}/coverage/jacoco.exec"/>
    <property name="sonar.junit.reportsPath" value="${junit.reports}" />
    <property name="sonar.jacoco.itReportPath" value="${junit.reports}/coverage/jacoco-it.exec"/>
    <property name="sonar.coverage.exclusions" value="<some modules>"/>
<sonar:sonar/>
</target>

Update 2: I looked at the sonar code in EmbeddedScanner.java, IsolatedLauncherFactory.java, and IsolatedLauncherProxy.java which actually should be throwing the error. I also ran the ant command in -v mode and below is the output of it:

Project.sonar:
[antlib:org.sonar.ant] Could not load definitions from resource org/sonar/ant/antlib.xml. It could not be found.
[sonar:sonar] Apache Ant(TM) version 1.10.5 compiled on July 10 2018
[sonar:sonar] SonarQube Ant Task version: 2.5
[sonar:sonar] Loaded from: file:<redacted_path>/sonarqube-ant-task-2.5.jar
[sonar:sonar] keyStore is : 
[sonar:sonar] keyStore type is : jks
[sonar:sonar] keyStore provider is : 
[sonar:sonar] init keystore
[sonar:sonar] init keymanager of type SunX509
[sonar:sonar] User cache: /Users/<user.name>/.sonar/cache
[sonar:sonar] Extract sonar-scanner-api-batch in temp...
[sonar:sonar] Get bootstrap index...
[sonar:sonar] Download: https://sonarcloud.io/batch_bootstrap/index
[sonar:sonar] Get bootstrap completed

So looking at the code and its output I think below is the code flow:

EmbeddedScanner.checkLauncherExists() --> IsolatedLauncherFactory.createLauncher() --> JarDownloader.download() --> JarDownloader.getScannerEngineFiles() --> BootstrapIndexDownloader.getIndex()

From the log, it seems that the index was returned successfully. But either the JarDownloader.getScannerEngineFiles() or JarDownloader.download() failed because the log statement logger.debug("Create isolated classloader..."); right after List<File> jarFiles = jarDownloader.download() in IsolatedLauncherFactory.createLauncher() is not printed.

Reference: Sonar source code available here

Bhavik Bhagat
  • 960
  • 8
  • 19
  • You're getting an exception thrown in the `finally` block of the scanner task (https://github.com/SonarSource/sonar-scanner-ant/blob/6cfc212ff2799663a4c52ea952b25256b96c6d89/sonarqube-ant-task/src/main/java/org/sonarsource/scanner/ant/SonarQubeTask.java#L101) so the original exception is being masked. Do you have a minimal build script and list of Sonar Ant libraries you're using to allow replication of this? – mc1arke Apr 20 '19 at 09:32
  • @mc1arke Updated the question with what you are looking for. Is this information sufficient? – Bhavik Bhagat Apr 21 '19 at 21:34

1 Answers1

5

Your issue is that sonar-ant-plugin does not seem to support SonarCloud. The plugin depends on an old version of sonar-scanner-api which attempts to retrieve a list of Jars to download by retrieving /batch_bootstrap/index from the remote SonarQube server. SonarCloud doesn't provide such a URL, but does have /bootstrap/index which newer versions of sonar-scanner-api do use.

Update: version 2.6.0.1426 of the scanner for Ant has been released to fix the issue.

mc1arke
  • 1,030
  • 10
  • 22
  • thanks for you investigation and the fix. Really appreciate it. But this thing has been working as it is since a year at least and we have done zero change on our side. Does it mean some change on sonar cloud caused this issue? This issue started happening 17th April, 2019 11:24 pm onwards and before that it always worked. – Bhavik Bhagat Apr 22 '19 at 23:54
  • 1
    I downloaded the jar from your snapshot and it works. Thanks once again for the fix. – Bhavik Bhagat Apr 23 '19 at 00:16
  • 1
    Yes. SONAR-11883 removed the redirection for old scanners on 3rd April (https://github.com/SonarSource/sonarqube/commit/18f71d6eb0de22c60f95281b367a1afaac8b5fda#diff-b0c30f360731e897969a4c2c702655c5). This hasn't been added to a release of SonarQube yet but SonarCloud seems to run pre-release versions so it's likely they deployed this change around the time your failure started. – mc1arke Apr 23 '19 at 07:05