Spring Web related dependencies not resolved

已回答

I'm currently running IntelliJ IDEA 2023.2.2 (Ultimate Edition).

I've got a project that compiles whenever I run gradle build.  There are no compilation errors whatsoever.  Only a few warnings about some deprecations.  When I import this project in IntelliJ, the gradle window shows all of the sub projects, and I can successfully rebuild the project from IntelliJ Idea.

However, IntelliJ Idea is incorrectly telling me that every class that extends OncePerRequestFilter doesn't actually implement the correct methods.  But it clearly does.

When trying to view the contents of OncePerRequestFitler, I'm met with this confusing file saying that the bytecode doesn't match.  And curiously, all the the jakarta imports cannot be resolved:

Showing the diff does show shows that IntelliJ's own decompiler can resolve the jakarta imports, but the actual sources it cannot:

 

I'm unsure what to do here, because again: the project compiles, runs tests, and brings up the app successfully when using gradle directly from the terminal.  And Intellij doesn't.  But I've currently got 91 “errors” related to this issue.  IntelliJ Idea doesn't seem to be resolving dependencies from spring-web correctly.  And as far as I can tell, it's only dependencies from spring-web.

My latest attempt at fixing this involved:

- Closing the Project, deleting the .idea folder, and invalidating caches and restarting intellij

- Completely deleting my ~/.gradle directory, uninstalling gradle, and then reinstalling

- Reimporting the project in Intellij, reloading the gradle scripts, and rebuilding the project

 

But at the moment this problem still persists.  It's not terrible, because I could learn to ignore them.  But I'd rather I could trust IntelliJ when it says I have a problem.  I'm sure I have a problem somewhere, I'm just not sure where.

 

1

What org.springframework:spring-web dependency version is used in the project and how did you add it?

I can reproduce it only if I explicitly add 

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>6.0.12</version>
</dependency>

but it works fine with

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

1

Thank you!

We pull in dependencies through multiple sub-projects/modules.  Each one pulls in the specific dependency they need.  Some pull in 

implementation("org.springframework:spring-webmvc:${libs.versions.springFramework.get()}")

Whereas others pull in

implementation("org.springframework:spring-web:${libs.versions.springFramework.get()}")

With the overall end product (the spring application itself) will pull in

implementation("org.springframework.boot:spring-boot-starter-web:${libs.versions.springBoot.get()}")

You've given me enough of a hint to know that the problem is somewhere within the gradle dependencies, and not something specifically with my IntelliJ Idea configuration.  That'll hopefully be enough for me to find and fix the offending imports

0

It seems the problem is that org.apache.tomcat.embed:tomcat-embed-core library is missing in the module dependencies

The following setup works fine for me

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>10.1.13</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>6.0.12</version>
</dependency>

1

Egor Klepikov , thank you for all the help you've given.  I've been trying to resolve the dependencies myself but I'm at a loss.  I can confirm that if I use a demo project I can reproduce the error and fix it by adding tomcat-embed-core as a dependency.  However this does not seem to work for my actual project.  I've played around with dependencies for a few days now and nothing seems to take.  At this point, I was curious if you knew if there is any way to just force IntelliJ IDEA to silence these errors if possible.

0

I was curious if you knew if there is any way to just force IntelliJ IDEA to silence these errors if possible

It seems the only way in this case is to use `File | Enable Power Save Mode`

However this does not seem to work for my actual project.  I've played around with dependencies for a few days now and nothing seems to take

You can try using Gradle tasks to better understand a project / modules structure https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html

 

 

0

Egor Klepikov , thanks again for all your help.  I tried both of the suggestions you provided to see if I could find anything new.  They didn't pan out for me, unfortunately.

I stripped down the project and excluded most of the modules from the build, so that only 5 modules were part of the build, giving me an easier time when working through the dependencies.  I couldn't find anything wrong with them when I did that.  But for whatever reason, when I tried specifying Spring Boot 3.2.0-M3 instead of 3.1.4, the problem went away.  Switching back to 3.1.4 consistently reproduces the issue, and switching to Spring Boot 3.2.0-M3 seems to resolve it.

I suppose for the time being I'll just wait for Spring 3.2 to be released next month.  Until then, I'll work off of the milestones and release candidates.

Thank you, Egor!

0

请先登录再写评论。