I want to exclude one dependency when I'm doing deploy, I need it when I use the jar locally, but it should not be in deployed jar. is there any way to do it?
Maybe a good solution is to set the dependency with a <scope>provided</scope>
. This way, the dependency will not be deployed.
However, locally, you will need to add the dependency in your classpath...
It depends on what you mean by "use the jar locally".
If you mean that you don't want the jar to be included in any bundles, you can set the scope of the dependency to provided
. This scope is only available on the compilation and test classpath, and is not transitive. A dependency with this scope will not be included in wars/ears.
<dependency>
<groupId>some.groupid</groupId>
<artifactId>my-dependency</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
If you mean you don't want the jar to be bundled into a distribution built with the assembly plugin, you can configure the assembly to exclude a specific dependency.
<profile> <id>localProfile</id> <activation> <property> <name>!deploy</name> </property> </activation> <dependencies> <dependency> ... </dependency> </dependencies> </profile>
when i run it with
mvn deploy -D deploy=0
the jar doesnt have that dependency