Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: how to add a dependency as provided for runtime, but explicitly for test?

In my current project that runs on a JBoss server it is required to add all dependencies as providedif they are provided by JBoss. However for my unit-tests I do need those libraries without the JBoss server providing them (i.E. javaee-api), but I cannot add the same dependency twice with different scopes.

How can I add a dependency as provided for runtime, but as test for unit tests?

like image 939
TwoThe Avatar asked Mar 15 '18 10:03

TwoThe


People also ask

How do I add dependency to runtime?

To add runtime dependenciesIn the "Classpath Entries" section of the Runtime tab, click Add and navigate to the required JAR file. Only JARs that are added to the list of runtime dependencies will be included when you deploy the plug-in.

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

What is runtime dependency in Maven?

runtime This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

What is test dependency in Maven?

A test -scoped dependency is a dependency that is available on the classpath only during test compilation and test execution. If your project has war or ear packaging, a test -scoped dependency would not be included in the project's output archive.


1 Answers

A provided dependency is available on the test classpath, so setting the scope to provided should be fine. See also the definition of provided:

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

like image 101
J Fabian Meier Avatar answered Oct 23 '22 23:10

J Fabian Meier