How to properly use maven library in plugin test case? Everything I tried, fails with java.lang.RuntimeException: java.io.IOException: Cannot find IntelliJ IDEA project files at
I have tried every permutation of JavaCodeInsightFixtureTestCase and LightJavaCodeInsightFixtureTestCase, with DefaultLightProjectDescriptor, with my own implementation of LightProjectDescriptor, with JavaModuleFixtureBuilder. As soon as I have a maven library added to the test case module, I get the same exception:
java.lang.RuntimeException: java.io.IOException: Cannot find IntelliJ IDEA project files at /Users/vlad/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2021.3/75777e10a0e2880bc02945066dda2480a696c3d9/ideaIC-2021.3
at com.intellij.testFramework.LightPlatformTestCase.initProject(LightPlatformTestCase.java:216)
at com.intellij.testFramework.LightPlatformTestCase.lambda$doSetup$2(LightPlatformTestCase.java:274)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:437)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:455)
at com.intellij.testFramework.LightPlatformTestCase.doSetup(LightPlatformTestCase.java:265)
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(LightIdeaTestFixtureImpl.java:40)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$setUp$28(CodeInsightTestFixtureImpl.java:1242)
at com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(EdtTestUtil.java:33)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.setUp(CodeInsightTestFixtureImpl.java:1241)
at com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.setUp(LightJavaCodeInsightFixtureTestCase.java:105)
at com.intellij.testFramework.UsefulTestCase.invokeSetUp(UsefulTestCase.java:476)
at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:468)
at com.vladsch.plugin.test.util.LightJavaCodeInsightFixtureSpecTestCase.defaultRunBare(LightJavaCodeInsightFixtureSpecTestCase.java:138)
at com.intellij.testFramework.UsefulTestCase.lambda$runBare$12(UsefulTestCase.java:541)
at com.intellij.testFramework.EdtTestUtil.lambda$runInEdtAndWait$1(EdtTestUtil.java:40)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:303)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:407)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.io.IOException: Cannot find IntelliJ IDEA project files at /Users/vlad/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2021.3/75777e10a0e2880bc02945066dda2480a696c3d9/ideaIC-2021.3
at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadProject(JpsProjectLoader.java:107)
at org.jetbrains.jps.model.serialization.impl.JpsSerializationManagerImpl.loadProject(JpsSerializationManagerImpl.java:38)
at com.intellij.project.IntelliJProjectConfiguration$Companion.loadIntelliJProject(IntelliJProjectConfiguration.kt:90)
. . .
Another post https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000150744-Error-during-Java-compilation-in-plugin-unit-test mentions that the project is not saved but JPS expects it to be saved. However, this post is from 2018 and the solution is not clear.
If I download the jar files into a subdirectory and add the files instead of maven coordinates, the test works. I am trying to eliminate manual configuration.
What is the right way to use Maven libraries in test cases?
请先登录再写评论。
Have you set `idea.home.path` https://plugins.jetbrains.com/docs/intellij/testing-faq.html#how-to-test-a-jvm-language?
Yes, I have:
test {systemProperty "idea.home.path", "/Users/vlad/src/JetBrains/intellij-community.master"
}
in the gradle build. Before adding the source to gradle build, the mock jdk configuration in the tests would fail. Having solved the mockJDK configuration issues in the tests, using any maven dependencies in the test results in the exception above.
Yann,
Just to update status. I went old school on this and defined maven libraries for my dependencies in the project structure. All libraries are configured to download to lib/ subdirectory in the project, with sources and transient dependencies. I did not add the libraries to any modules since their only purpose is to download the jars.
I then copied the classes entries from the library .xml file under .idea/libraries, without the jar:// prefix and ! suffix. Pasted these jars as a dependency in my test's LightProjectDescriptor jar files list. Added code to handle the $PROJECT_DIR$ replacement to project directory in my LightProjectDescriptor implementation.
These tests now run. It really is maven library dependencies that were causing a the exception.