I have a dependency which I have installed in Maven local repository and is being used locally but is not available on deployment server. I use that dependency using Class.forName(...)
so there will be no problem if it's missed from classpath on deployment server.
Is there any way to tell Maven to ignore a dependency if it failed to resolve it?
I doesn't seem that <scope>
or <optional>
can solve this problem, but it may be possible to do it with <profiles>
if there is any way to activate/deactivate a profile based on dependencies availability.
You can use Exclude command from the context menu in the Maven dependency diagram to quickly exclude the specified dependency from POM and the respective tool windows. The dependency is also excluded from the Project and Maven tool windows.
There we can exclude all transitive dependencies without specifying groupId and artifactId of the dependencies. So need to use astric(*) character as groupid and artifactid of the dependency. This wildcard transitive dependencies ignoring is available with maven 3.2.
Exclusions are set on a specific dependency in your POM, and are targeted at a specific groupId and artifactId. When you build your project, that artifact will not be added to your project's classpath by way of the dependency in which the exclusion was declared.
Short answer: no.
Long answer: Once dependency is declared - either in common part or in an active profile - it must be resolvable when Maven attempts it; otherwise the build fails.
If maven allowed the requested behavior, the reproducibility of build would suffer a lot.
If obscurity and irreproducibility is not an issue for you, here is a hint how to do it:
In any case, I strongly discourage including such things into maven build. Having it as separate functionality, invoked via ant from commandline, might often be enough.
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