Skip to content

IntelliJ 'Run' cannot execute tests (IllegalAccessError: com.intellij.testFramework.UITestUtil); running via Gradle world #1757

Open
@sewe

Description

@sewe

What happened?

I have a build using org.jetbrains.intellij.platform (using the latest version: 2.0.1) with some tests using the IdeaTestFixtureFactory.

On the command-line using ./gradlew, these work fine.

They fail, however, when launching them using Run in IntelliJ (2024.2.1 Ultimate) with an

java.lang.IllegalAccessError: class com.intellij.testFramework.UITestUtil (in unnamed module @0x146ba0ac) cannot access class sun.awt.AWTAutoShutdown (in module java.desktop) because module java.desktop does not export sun.awt to unnamed module @0x146ba0ac

While I can, of course, configure the respective VM options manually, this is cumbersome, especially when frequently switching between tests and letting IntelliJ create the launch configurations on the fly.

Relevant log output or stack trace

java.lang.IllegalAccessError: class com.intellij.testFramework.UITestUtil (in unnamed module @0x146ba0ac) cannot access class sun.awt.AWTAutoShutdown (in module java.desktop) because module java.desktop does not export sun.awt to unnamed module @0x146ba0ac

	at com.intellij.testFramework.UITestUtil.replaceIdeEventQueueSafely(UITestUtil.java:73)
	at com.intellij.testFramework.UITestUtil.setupEventQueue(UITestUtil.java:60)
	at com.intellij.testFramework.common.TestApplicationKt.loadApp(testApplication.kt:107)
	at com.intellij.testFramework.common.TestApplicationKt.loadApp(testApplication.kt:95)
	at com.intellij.testFramework.common.TestApplicationKt.doInitTestApplication(testApplication.kt:86)
	at com.intellij.testFramework.common.TestApplicationKt.initTestApplication(testApplication.kt:76)
	at com.intellij.testFramework.TestApplicationManager$Companion.getInstance(TestApplicationManager.kt:59)
	at com.intellij.testFramework.TestApplicationManager.getInstance(TestApplicationManager.kt)
	at com.intellij.testFramework.fixtures.impl.BareTestFixtureImpl.setUp(BareTestFixtureImpl.java:17)
	at com.teamscale.ide.intellij.testing.BareTestFixtureTestBase.setUp(BareTestFixtureTestBase.java:22)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Steps to reproduce

My tests specify an explicit JBR:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
        vendor = JvmVendorSpec.JETBRAINS
    }
}

and this is indeed picked up when IntelliJ creates the launch configuration:

/home/sewe/.gradle/jdks/jetbrains_s_r_o_-17-amd64-linux.2/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/home/sewe/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate/lib/idea_rt.jar=38771:/home/sewe/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate/bin -Dfile.encoding=UTF-8 @/tmp/idea_arg_file839703118 com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 com.teamscale.ide.intellij.servers.JnaSmokeTest,testIntelliJExposesJnaLibrary

Gradle IntelliJ Plugin version

2.0.1

Gradle version

8.9

Operating System

Linux

Link to build, i.e. failing GitHub Action job

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions