且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果无法解决依赖关系,如何告诉Maven忽略它呢?

更新时间:2023-09-18 08:49:58

简短答案:否.

长答案:一旦声明了依赖关系(无论是在公共部分还是在活动配置文件中),当Maven尝试进行依赖时,它都必须是可解析的;否则,构建将失败.

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.

如果maven允许请求的行为,则构建的可重复性将受到很大影响.

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:

  • 使用exec-maven-plugin或maven-antrun-plugin从pom.xml调用外部蚂蚁
  • 在蚂蚁代码中,使用Maven Ant中的 artifact:dependencies 任务
  • 将其包装在ant-contrib的 trycatch
  • call external ant from your pom.xml, using either exec-maven-plugin or maven-antrun-plugin
  • in the ant code, use artifact:dependencies from Maven Ant Tasks
  • wrap it in ant-contrib's trycatch block

无论如何,我强烈不鼓励将这些东西包括进Maven构建中.将其作为单独的功能(通过命令行中的ant调用)通常就足够了.

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.