1

I have a my-api which depends on A-api.

And my client will dependent on A-api explictly , so I may propable need to declare this dependency as provided.

Rather than declare a hard-coded version dependeny on A-api at my my-api's pom, I want a lowest version, since A-api's team will garanteer that its Api will be compatable with the former one

my-api's pom:

            <dependency>
                <groupId>org.mygroup</groupId>
                <artifactId>A-api</artifactId>
                <version>a-at-least-version</version><!--I only want a lowest version that i need-->
                <scope>provided</scope><!--Should I declare it as provided? -->
            </dependency>

my client will use our two api like:

        <!--Notice, my client will explicitly declare dependency on A-api, and this may be higher than what my-api dependent on. This api will update more frequently than my-api-->
            <dependency>
                <groupId>org.mygroup</groupId>
                <artifactId>A-api</artifactId>
                <version>may-be-a-newer-version</version>
            </dependency>

            <!--My client will also dependent on my-api with a statble version-->
            <dependency>
                <groupId>org.mygroup</groupId>
                <artifactId>my-api</artifactId>
                <version>one-version</version>
            </dependency>
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
  • Could you clarify why you need declare dependency to A-api as provided? Why is not enough to declare dependency to client-api? – michaldo Sep 06 '16 at 07:24
  • @michaldo , please check my updated question. – JaskeyLam Sep 06 '16 at 13:40
  • Let say lowest version of A-api is 1.0.0 and my-api:one-version depends on A-api:1.0.0. Your client will depends on A-api:2.3.4 and my-api:one-version. Where is a problem? – michaldo Sep 06 '16 at 13:54
  • @michaldo, so in this case, even though I declare I dependent on my-api 1.0.0 as provided scope, my client will not have any compile or package problem when it delcare depends on A-api 2.3.4? And it will only have one api jar on its lib? – JaskeyLam Sep 07 '16 at 01:48
  • In this case your client will work with A-api:2.3.4 (maven applies "nearest wins strategy", for your client dependency to A-api:2.3.4 has level 1 and dependency to A-api:1.0.0 has level 2, level 1 is nearest than level 2). BTW, within your library you don't have to configure the dependency as "provided". "Provided" tells war-plugin not include the dependency to target WAR (for example servlet API should not be included to WAR because is provided by container). Your case is not related to WAR (or EAR) packaging and plain scope "compile" is better – michaldo Sep 07 '16 at 06:57
  • But they will have api 2.3.4 along with api1.0.0 in my client's classpath insn't it , where can I find some explaination about "nearest wins strategy" ? – JaskeyLam Sep 07 '16 at 13:45
  • Nearest win: http://guntherpopp.blogspot.com/2011/02/understanding-maven-dependency.html and http://stackoverflow.com/a/38984830/2365727 – michaldo Sep 07 '16 at 13:58

1 Answers1

0

Seems this question has already been answered via comments by @michaldo, but if you're hell-bent on doing it your way, you can use this notation.

<dependency>
    <groupId>org.mygroup</groupId>
    <artifactId>A-api</artifactId>
    <version>[x.y,)</version><!--I only want a lowest version that i need-->
    <scope>provided</scope><!--Should I declare it as provided? -->
</dependency>

Please refer to the Maven docs on resolving version ranges.

Mig82
  • 4,856
  • 4
  • 40
  • 63