Correct way to declare multiple scope for Maven dependency?

前端 未结 4 1812
离开以前
离开以前 2021-02-03 17:05

I have a dependency that I want to use in test scope (so that it is in the classpath when I am running unit tests), and in runtime scope (so that I can

4条回答
  •  自闭症患者
    2021-02-03 17:26

    Not sure if this would still help someone who is still looking for a simple way to do this - https://howtodoinjava.com/maven/maven-dependency-scopes/ this link helped me add the correct scope. Here is the summary of mapping of scopes and the phases where we need the dependencies.

    1. compile - build, test and run
    2. provided - build and test
    3. runtime - test and run
    4. test - compile and test

    So, when I needed the dependency during test and runtime, I gave the scope as "runtime" and it worked as expected.

提交回复
热议问题