0

I have this pair of dependencies in my pom.xml:

    <dependency>
      <groupId>org.springframework.security.oauth.boot</groupId>
      <artifactId>spring-security-oauth2-autoconfigure</artifactId>
      <version>2.6.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.security.oauth.boot</groupId>
      <artifactId>spring-security-oauth2-autoconfigure</artifactId>
      <version>2.6.7</version>
      <scope>compile</scope>
    </dependency>

You can see that it's the same dependency, only under two different scopes. It would be perfect if Maven allowed for something like <scope>test,compile</scope> but, alas, it does not.

Since both my IDE and Maven warn me about duplicate dependencies, I was wondering whether there is any way for me to compress these dependency declarations into one.A screenshot of my IDE with the pom.xml in focus.

If you need to copy the maven warning, here you go:

[WARNING] Some problems were encountered while building the effective model for org.finra.mdrepo.apollo:moonshot:jar:0.1
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:jar -> duplicate declaration of version 2.6.7 @ line 563, column 17
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

This SO post details that the runtime scope implies the test scope, but it also seems to be used entirely separately from the compile scope (which makes sense). So the solution of just using runtime would not work for me.

Jason
  • 2,495
  • 4
  • 26
  • 37
  • Use only the compile scoped dep because a dep which is available via compile scope is available in tests as well. The difference makes no sense here.. – khmarbaise Nov 02 '22 at 10:58

0 Answers0