I believe you are worrying about something that is not going to happen. Conflicting versions between different dependencies on the same artifact will be resolved by a process called dependency mediation, and Maven will not pull in multiple versions of the same artifact onto the same classpath. E.g., if you make your library your-group:your-library:1.0
depend on org.springframework:spring-context:3.2.4.RELEASE
, and my project my-group:my-artifact:1.0
depends on both org.springframework:spring-context:3.1.4.RELEASE
and your-group:your-library:1.0
, then Maven will only pull version 3.1.4
of spring-context
into my build, not both 3.1.4
and 3.2.4
. If your library also depends spring-beans:3.2.4
and there happens to exist some incompatibility between spring-context:3.1.4
and spring-beans:3.2.4
, then you can consider it the responsibility of my project to add spring-beans
as a dependency and explicitly override its version to 3.1.4
in my-artifact
's POM.
That being said, you can sort of accomplish what your question is directly asking by using version ranges:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>[3.0.0.RELEASE,3.2.16.RELEASE]</version>
</dependency>
This will effectively tell projects depending on your library that your library is okay with any existing 3.X
version of spring-context
, but version ranges have their own set of rules during dependency mediation that can possibly be unfriendly and obscure, and they won't link up between different artifacts either, so I would recommend just sticking with a regular version number in your case.