stale classpath when running under IDEA

已回答

I deleted most of the dependencies of an application module, but when I run the application (using the classpath of the module), the classpath is the old classpath with all of the deleted dependencies. How can I fix this? Cache invalidation did not help.

0

Hello,
Here are the most effective ways to force a classpath refresh, depending on your environment:

1. Force a "Clean" Build
This is the most common culprit. Your IDE or build tool might not have deleted the actual .jar files or compiled classes from the output directory.

Maven: Run mvn clean install. The clean lifecycle specifically deletes the target/ directory where the old classpath is constructed.

Gradle: Run ./gradlew clean. This removes the build/ directory.

IntelliJ IDEA: Go to Build > Rebuild Project. This forces the IDE to re-examine the dependency tree from scratch.

2. Refresh the Build Tool Import
Sometimes the IDE's internal model of the project gets "stuck," even if you’ve invalidated the caches.

IntelliJ: Open the Maven or Gradle sidebar on the right and click the Reload All Maven/Gradle Projects icon (the two circular arrows).

Eclipse: Right-click the project > Maven > Update Project... (ensure "Force Update of Snapshots/Releases" is checked).

3. Check for "Transitive" Dependencies
If you deleted a direct dependency e-zpassin but it is still showing up in the classpath, it might be coming in as a transitive dependency (a dependency of one of your remaining dependencies).

To verify:

Maven: Run mvn dependency:tree

Gradle: Run ./gradlew dependencies

The Fix: Use an <exclusion> tag in Maven or an exclude rule in Gradle to explicitly block those unwanted jars.

4. Inspect Run/Debug Configurations
If the application runs with the old classpath only when you click the "Run" button in your IDE, the issue might be in the Run Configuration itself.

Check if there are hardcoded classpath entries or "VM Options" in the configuration that point to specific folders or old library versions.

Try deleting the existing Run Configuration and creating a new one from scratch to let the IDE regenerate the classpath based on the current state of the pom.xml or build.gradle.

5. Clear Local Repository (Last Resort)
If the build tool thinks a specific version is required and it exists in your local cache (~/.m2/repository or ~/.gradle/caches), it might keep pulling it in.

Try deleting the specific folders for the deleted dependencies within your local .m2 or Gradle cache directory to ensure the build tool can't find them anymore.

0

I think I have discovered the source of this problem. The IDEA module whose dependencies I changed is present in two IDEA projects. Changing the dependencies in one project has no effect on the dependencies displayed in the other project, even if that project is closed and reopened, or rebuilt, or reloaded from disk. It is possible that clearing the file system cache would fix the problem, but that also clears the local history, which I do not want to do. Is there a more gentle way to solve this problem?

Actually, I think I just found a solution: remove the module from the other project then add it back. Wrong. That fixes what is displayed, but it doesn't change the class path when the module is run. Even deleting and recreating the run configuration does not help.

 

0

Hi Alan Snyder , may I know in which place these dependencies are removed? In Project Strucutre, or local disk (.m2 folder or some other places), or from the build file of Maven/Gradle?

0
Hi Alan, the Project Structure's dependencies are created based on the Gradle build file when the project is opened. So please don't edit these settings, please edit build.gradle(.kts) instead.
0

Hi Alan, if possible, could you share a sample project? You can upload it to https://uploads.jetbrains.com/ and paste the upload id here; the uploaded file is only visible to JetBrains employees. If you are using Maven, I'd like to say that since there are a lot of similar issues comes from inconsist from build files such as pom.xml with Project Structure, as every time the project is opened, the Project Structure will be synced to the build files, in the future version of IDEA, the Project Structure will be removed.

0

@jacky liu I don't use Maven, either. :-)

0

Thanks for the update. Could you share the log files at https://uploads.jetbrains.com/ via the menu Help > Collect logs and Diagnostic Data? Can you check whether the contents of the xxx_.iml file been changed after you modified the project structure?

eg:
 

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="github.log4jdbc.forjdbi" level="project" />
    <orderEntry type="library" name="test" level="project" />
  </component>
</module>

<orderEntry type="library" is the modified library settings.

0

The IML file was updated. The content timestamp is 21 Jan. I mention the date because the project that previously displayed stale Project Structure now displays the current Project Structure. So, something I did in the last five days caused the project to update, but I don't know what that was. I did not clear the file system cache.

Upload id: 2026_01_26_d8bnH7nvsxJgwkPi5EsBfi (file: idea-logs-20260126-1204503694232961128208482.zip)

0

Hi Alan, I've checked the log files and only see errors from the debugger and Ant plugin. Can you right-click the .idea folder, then choose Local History | Recent Changes, to see why the file changed and the old version of its contents?

0

It shows an external change to the .iml file on 21 January. The change is a replacement of several modules with a few libraries. That is the change that I made via Project Structure.

0

Hi Alan,

Can you share a sample project without sensitive info for this? You may copy your current project folder and remove the sensitive source code, and then I'll file an issue report about this.

0

What's missing in this conversation is that two projects are involved. One module open in two projects. I don't think there is anything special about the projects or the module.

Some questions I have:

I assume the classpath of each module is cached. Where exactly is the cache? Is it in a database somewhere?

In the one module two project case, is there one cache shared by both projects or does each project have its own cache of the module classpath?

What operations invalidate the cache of the module classpath? For example, does Reload All From Disk invalidate this cache? Does Reload All From Disk operate on the active project only or on all open projects?

 

0

It's more likely a bug in the IDEA Java runner. Please try the menu File | Cache Recovery | Repair IDEto see if it helps.

0

I'll do that if the problem recurs.

 

0

请先登录再写评论。