CodexBloom - Programming Q&A Platform

Maven scenarios to resolve dependency with scope 'provided' in a multi-module project with JUnit 5

πŸ‘€ Views: 80 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-25
maven junit5 multi-module Java

I tried several approaches but none seem to work. I've hit a wall trying to I'm building a feature where I'm working with an scenario where Maven want to resolve a dependency with scope 'provided' for JUnit 5 in my multi-module project. My parent POM has the following dependency defined: ```xml <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.7.0</version> <scope>provided</scope> </dependency> ``` However, when I run `mvn clean install`, I get the following behavior in one of my child modules: ``` [behavior] Failed to execute goal on project my-module: Could not resolve dependencies for project com.example:my-module:jar:1.0-SNAPSHOT: Failure to find org.junit.jupiter:junit-jupiter-api:jar:5.7.0 in central (https://repo.maven.apache.org/maven2) was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced ``` I've tried cleaning the local repository with `mvn clean install -U` and ensured that my settings.xml is properly configured to point to the central repository. I also verified that JUnit 5 is correctly defined in the parent POM. Additionally, I ensured that the scope of JUnit in my test classes is set to 'provided', but I still see the behavior. Here’s how I define my test dependency in the child module: ```xml <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> ``` Is there something I might be missing in my configuration? Or could this be an scenario with the scope resolution in a multi-module setup? Any insights would be greatly appreciated! For context: I'm using Java on Ubuntu. Has anyone else encountered this? This is happening in both development and production on Debian. What's the correct way to implement this? Could someone point me to the right documentation? I appreciate any insights!