1

Using Sonarqube Gradle plugin version 6.2.0.5505 (latest: https://plugins.gradle.org/plugin/org.sonarqube/6.2.0.5505) , the analysis of Kotlin source code fails when running on my Jenkins instance, with following stack trace:

10:20:44  [stderr] Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':99.0' as the value of the DISPLAY variable.
10:20:44  [stderr]  at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
10:20:44  [stderr]  at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(Unknown Source)
10:20:44  [stderr]  at java.base/java.security.AccessController.doPrivileged(Unknown Source)
10:20:44  [stderr]  at java.desktop/sun.awt.X11GraphicsEnvironment.initStatic(Unknown Source)
10:20:44  [stderr]  at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(Unknown Source)
10:20:44  [stderr]  at java.desktop/sun.awt.PlatformGraphicsInfo.createGE(Unknown Source)
10:20:44  [stderr]  at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(Unknown Source)
10:20:44  [stderr]  at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(Unknown Source)
10:20:44  [stderr]  at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(Unknown Source)
10:20:44  [stderr]  at java.desktop/sun.awt.X11.XToolkit.<clinit>(Unknown Source)
10:20:44  [stderr]  at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(Unknown Source)
10:20:44  [stderr]  at java.desktop/java.awt.Toolkit.getDefaultToolkit(Unknown Source)
10:20:44  [stderr]  at java.desktop/java.awt.Toolkit.getEventQueue(Unknown Source)
10:20:44  [stderr]  at java.desktop/java.awt.EventQueue.isDispatchThread(Unknown Source)
10:20:44  [stderr]  at java.desktop/javax.swing.SwingUtilities.isEventDispatchThread(Unknown Source)
10:20:44  [stderr]  at com.intellij.mock.MockApplication.isDispatchThread(MockApplication.java:91)
10:20:44  [stderr]  at org.jetbrains.kotlin.analysis.api.impl.base.permissions.KaBaseAnalysisPermissionChecker.isProhibitedEdtAnalysis(KaBaseAnalysisPermissionChecker.kt:63)
10:20:44  [stderr]  at org.jetbrains.kotlin.analysis.api.impl.base.permissions.KaBaseAnalysisPermissionChecker.isAnalysisAllowed(KaBaseAnalysisPermissionChecker.kt:37)
10:20:44  [stderr]  at org.jetbrains.kotlin.analysis.api.impl.base.sessions.KaBaseSessionProvider.beforeEnteringAnalysis(KaBaseSessionProvider.kt:56)
10:20:44  [stderr]  at org.jetbrains.kotlin.analysis.api.impl.base.sessions.KaBaseSessionProvider.beforeEnteringAnalysis(KaBaseSessionProvider.kt:48)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.visiting.KotlinFileVisitor.scan(KotlinFileVisitor.kt:73)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.sensors.AbstractKotlinSensorExecuteContext.analyzeFile$lambda$8$lambda$7(AbstractKotlinSensorExecuteContext.kt:120)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.common.MeasureDurationKt.measureDuration(MeasureDuration.kt:23)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.sensors.AbstractKotlinSensorExecuteContext.analyzeFile(AbstractKotlinSensorExecuteContext.kt:119)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.sensors.AbstractKotlinSensorExecuteContext.analyzeFiles$lambda$6$lambda$5(AbstractKotlinSensorExecuteContext.kt:102)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.common.MeasureDurationKt.measureDuration(MeasureDuration.kt:23)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.sensors.AbstractKotlinSensorExecuteContext.analyzeFiles(AbstractKotlinSensorExecuteContext.kt:101)
10:20:44  [stderr]  at org.sonarsource.kotlin.api.sensors.AbstractKotlinSensor.execute(AbstractKotlinSensor.kt:65)
10:20:44  [stderr]  at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
1

The build is run on a Jenkins docker agent based on debian image. I had similar issue with older version of Sonarqube plugin , like https://plugins.gradle.org/plugin/org.sonarqube/4.4.1.3373 : it was possible to workaround this issue by forcing Gradle process to start in Headless Mode, using -Djava.awt.headless=true

With latest version 6.x of sonarqube plugin, this workaround is no longer working.

Note: running the sonar analysis locally on my Windows dev environment is working fine.

Any suggestion ?

2 Answers 2

0

It complains:

Can't connect to X11 window server ...

When there is no X11 window server available, this may either be caused be caused a) by -Djava.awt.headless=ture, which should be removed or b) there is indeed no window server available to user jenkis. Besides X11 server, the least would be a local VNC server, where user jenkis is permitted to connect to. That's most easy to setup, when logging in as user jenkis.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand why Sonar would require a X11 server or use java.desktop/sun.awt packages internally to perform kotlin code static analysis, this does not make sense to me. this is the aim of this SO question: is there any way to disable this X11/desktop prerequisite to make analysis possible on the full linux/debian CI infrastructure, as it was possible in previous plugin version ?
Maybe com.intellij.mock.MockApplication needs a GUI ...and when one cannot disable this anymore, all one can do is to provide Jenkins with an X11 window server, which means either an actual graphics adapter, or some VNC emulated desktop. It's just tricky to setup, as one has to change user jenkins, so that one can even log in as user jenkins, then setup the stuff and eventually disable interactive login again. You could as well try this on a local Jenkins instance, where X11 is already available.
0

You could try to run it using xvfb-run from the Xvfb project. It starts your application(s) under a fully compatible X Window server without any hardware and not a lot of overhead.

I've used this a few times to run UI tests and for an X11 desktop app that had command line arguments for use on the command line.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.