Home > other >  How to solve error: package org.springframework.context.annotation does not exist import org.springf
How to solve error: package org.springframework.context.annotation does not exist import org.springf

Time:12-24

After updating the gradle wrapper to version 7.3.2 I get the following error when trying to build my spring boot project:

error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.Bean;

Why is this happening?

Update: Found the problem, but do not know how to fix yet. I have multiple modules in my project. I have a "common" module which is used by other modules. With the old gradle version the libs of the common project were added to the compileClasspath of other modules, with the new version it adds them only to the runtimeClasspath.

The dependencies used to be declared as compile, now with gradle 7 I had to change them to implementation.

Any suggestions?

In other module:

    dependencies {
        implementation project(':common')
...
    }

In common module:

dependencies {
    implementation spring.web
...
}

CodePudding user response:

I think you have an issue with transitivity , if you use java-library instead of java plugin

plugins {
   id 'java-library'
}

https://docs.gradle.org/current/userguide/java_library_plugin.html#java_library_plugin
then you can use the api instead of compile which can help
you can see a good explanation What's the difference between implementation, api and compile in Gradle?

  • Related