In my current project that runs on a JBoss server it is required to add all dependencies as provided
if 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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With