IntelliJ can't find classpath test resource

intellij can't run main
intellij download
intellij can't select main class
jetbrains
intellij can t run anything
intellij http client plugin
intellij configuration
how to open intellij

I'm having a problem where IntelliJ 13.1.4, when running a unit test, can't find a ServiceLoader file in the src/test/resources directory of my module.

Please note before answering that I've done all of the following:

  1. The module is a Gradle project, and if I run gradle test the unit test runs fine.
  2. I've run this unit test successfully in IntelliJ in the past, and it found the module. (Maybe an earlier version of IntelliJ?)
  3. I've double checked the IntelliJ module settings and the src/test/resources directory is marked as being a test resources directory. (See screenshot below.)
  4. I'm dumping the unit test class's classloader's classpath in the class; it has the build/classes/test/ and build/classes/java directories, but neither build/resources/test/ nor build/resources/main/.
  5. I've clicked the button to refresh all Gradle projects.

Any ideas on what else could be causing IntelliJ to fail here?


Screenshot of my module configuration, showing the Test Resource Folders setting.

I managed to get it working better by creating a test-resources directory parallel to the test directory (!).

Still seeing intermittent problems with this, though. Those times, it's possible to open the IntelliJ project settings and define the test resources as source instead (the Gradle project will remain unchanged).

Must be an IntelliJ bug, as I've experienced the same thing in Android Studio.

EDIT:

I found a workaround to the issue.

Add the following at the end of the Gradle config (and specify your test resources path):

task copyTestResources(type: Copy) {
    from "${projectDir}/src/test/resources"
    into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources

HTTP client in IntelliJ IDEA code editor - Help, Physical files can be used for documenting, testing, and validating HTTP requests. Physical files are stored inside your project, and IntelliJ IDEA will not modify  IntelliJ IDEA is an integrated development environment written in Java for developing computer software. It is developed by JetBrains, and is available as an Apache 2 Licensed community edition, and in a proprietary commercial edition. Both can be used for commercial development.

I face a similar issue with IntelliJ 14. Despite having the necessary files in my resources folder and ensuring that the folder is specified as a resource in the module settings, IntelliJ intermittently fails to load my files onto the classpath.

One workaround is to add the required folder as a dependency for the module in the module settings.

First, click on the "+" button to add a new dependency.

Then, select the folder you wish to add to the classpath.

Then select the "classes" option.

Once that is done, re-build your module once and hopefully that should do the trick.

Ideally this should not at all be an issue. All files in the resource folder should directly be put in the classpath. However, every IDE has it's quirks.

NetBeans - Help, IntelliJ IDEA will add the necessary definition files (the .idea directory) to your project directory. The NetBeans .nbproject directory and build.xml will remain  Also - while I can't see all of your source code - be sure that it's proper Java syntax, with a class declared the same as the file and that it has a main method (specifically public static void main (String [] args) ). IntelliJ won't run code without a main method (rather, it can't - neither it nor Java would know where to start).

When I was running into the same issue, it worked for me to once unmark the resources directory as resources root and then mark it again as resources root:

  1. Right click on resources folder > Mark directory as ... > Unmark as Resources Root
  2. Right click on resources folder > Mark directory as ... > Test Resources Root

Code reference information - Help, In IntelliJ IDEA, you can see where and how symbols, such as tags, classes, fields, methods, or functions are defined in your project. For this purpose, the IDE​  In IntelliJ IDEA 2020.1, you can invoke context-sensitive actions on the variable s (by using Alt + Enter or by clicking the yellow light bulb) and select ‘Replace ‘s’ with pattern variable’ to use pattern matching in Java 14: This modification introduces the pattern variable s (on line 5), which appears right after type String.

In my case, I simply ran the tests through maven command line, i.e. a basic mvn clean install. After that it worked in IDEA.

IntelliJ IDEA pro tips - Help, Invert boolean. If IntelliJ IDEA can automate type migration, why not do the same with semantics? To invert all usages of  The new Selenium plugin is only compatible with IntelliJ IDEA Ultimate. New project with Selenium and test libraries. Once the Selenium plugin is installed, you can create a UI test project directly from the New Project wizard.

HTML - Help, If the tag or the attribute is available in all versions of browsers, IntelliJ IDEA does not show any information about its compatibility. HTML quick documentation:  I am on a Mac OS X and it looks like I am having similar issues to that other issue. I can reproduce this and have the log output below: 2016-09-02 16:53:49,734 [ 52287] INFO - .diagnostic.PerformanceWatcher - Unindexed files update took 34836ms; general responsiveness: ok; EDT responsiveness: 1/35 sluggish, 2/35 very slow

IntelliJ Platform: Open Source Platform for Building Developer Tools, JetBrains hosts a plugin repository where any plugin can be published and installed on any IDE built on the platform. More information about the IntelliJ Platform  I am using Intellij Community and am having a strange issue. If a class depends on a class in the same package the ide can't seem to find it. The class is highlighted in red. If I explicitly import it instead (I shouldn't have to for classes in the same package) the red goes away. Building the project seems to be fine and produce no errors.

Projects - Help, In IntelliJ IDEA, there are two types of formats in which a project's configuration can be stored — the file-based format and the directory-based format. IntelliJ IDEA provides a tool for resolving conflicts locally. This tool consists of three panes. The left pane shows the read-only local copy; the right pane shows the read-only version checked in to the repository.

Run IntelliJ IDEA for the first time - Help, In IntelliJ IDEA, a module is an essential part of any project – it's created automatically together with a project. Projects can contain multiple modules – you can  IntelliJ IDEA tutorial for beginners: - Learn how to create your first Java application in IntelliJ IDEA - See how to select a JDK to use to compile the application - Find out where to access and

Comments
  • Resource patterns in the compiler dialog may be?
  • Good idea! I just checked that, and I have !?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj. I tried adding my filename to that, but it made no difference; the classpath printed when the test runs still doesn't include the src/test/resources/ dir.
  • I having the exactly same issue here... Intellij 13.1.4
  • What's your code for loading the resource?
  • @bacar: I don't load it myself directly; it's done by a library that I use (junit-quickchek). But I do know that the library uses the Java platform's ServiceLoader class.
  • Have you reported this to Jetbrains support? They're fairly responsive. I would have thought that a correct implementation of gradle support should not require explicitly copying the resources.
  • @bacar Looks like similar issue's already been reported: youtrack.jetbrains.com/issue/IDEA-128273
  • I did not get a chance to test your proposed solution, because somehow I can no longer reproduce my original problem.
  • As an update, the above noted IDEA bug is showing as a duplicate, primary bug is: youtrack.jetbrains.com/issue/IDEA-91952
  • Experiencing the same with Maven. Still. Any idea what the maven equivalent of your fix would be? I have tests that depend on some flat files and Maven finds them in the console but IntelliJ explodes claiming not to find them.
  • Thanks the fix worked! This seems still broken as of the date I am writing this comment.
  • This does work but the problem with this in a Gradle project is that any changes made to the module's setup will be lost the next time a Gradle sync happens (and thus the modules in the project are all refreshed). If there was a way to make this change by means of the module's build.gradle file that would be great!
  • @AdilHussain I was using maven for this. However, my unit tests were working by running maven using command prompt, but were failing when running via intelliJ. What I faced was IDE specific. Not build tool specific.
  • I am still facing this issue, haven't been resolved till now.