CodexBloom - Programming Q&A Platform

Maven fails to inherit dependency scope from parent POM in a multi-module setup

πŸ‘€ Views: 169 πŸ’¬ Answers: 1 πŸ“… Created: 2025-07-06
maven multi-module dependency-management xml

I'm updating my dependencies and I'm encountering an issue where my child module is not inheriting the dependency scope defined in the parent POM. In my parent POM, I have defined a dependency on `com.google.guava:guava:30.1.1-jre` with a scope of `provided`. However, when I run `mvn dependency:tree` in the child module, it shows that the scope is set to `compile`. Here’s my parent POM snippet: ```xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany</groupId> <artifactId>my-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>30.1.1-jre</version> <scope>provided</scope> </dependency> </dependencies> </dependencyManagement> </project> ``` In the child module POM, I simply reference the dependency without redefining the scope: ```xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.mycompany</groupId> <artifactId>my-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>my-child</artifactId> <version>1.0-SNAPSHOT</version> </project> ``` I’ve tried running `mvn clean install` and `mvn dependency:tree` multiple times, but I still see the scope as `compile`. I also verified that there are no overriding scopes in the child POM or any profiles that might be affecting this. This is leading to classpath issues in my application deployment since `Guava` is expected to be provided by the server. What could be causing this failure to inherit the scope properly? Any ideas? For reference, this is a production REST API. I'm working in a macOS environment. Any pointers in the right direction? I'm working with Xml in a Docker container on Windows 10. Cheers for any assistance!