有一个maven项目构建自己的依赖项? [英] Having a maven project build its own dependencies?

查看:112
本文介绍了有一个maven项目构建自己的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用maven是否可以拥有一个顶级项目,其包装类型是war,它将构建自身及其所有依赖模块(打包为jar)并使构建生成project.war文件?

With maven is it possible to have a top-level project who's packaging type is "war" which will build itself and all of its dependent modules (packaged as jar) and have the build generate a project.war file?

我见过的大部分文档示例和其他示例经常使用包装类型为pom的顶级项目,该项目仅用于绑定模块一起。我可以避免这种情况吗?

Much of the documentation examples and other examples I've seen often use a top-level project with packaging type of "pom" and the project only serves the purpose of tying the modules together. Can I avoid this?

所以基本上我需要的东西实际上就像声明一个< module> my-module< / module> for maven to build,在同一个POM中,声明< dependency> ... my-module的工件...< / dependency> 在需要构建的同一模块上。也许有人建议的插件?

So basically I need something which is effectively like declaring a <module>my-module</module> for maven to build, and in that same POM, declaring a <dependency>...my-module's artifact...</dependency> on that same module which needs to be built. Maybe a plugin as someone already suggested?

更新:换句话说(为了简化问题):如果我有项目A 项目B ,其中项目A 取决于项目B - 有没有办法让我在项目A 上执行构建,并让它自动构建项目B (包括项目B 作为其依赖项 - 创建包含projectB.jar的projectA.war)?

Update: In other words (to simplify the problem): If I have project A and project B, where project A depends on project B - is there a way for me to execute a build on project A and also have it automatically build project B (and include project B as its dependency - creating projectA.war which contains projectB.jar)?

推荐答案

这不是顶级项目的真正含义。您的WAR项目具有依赖项,这些依赖项是运行mvn package时将包含在WAR(在WEB-INF / lib中)中的工件(例如jar)。您的WAR项目pom可以将顶级项目作为其父项,但它不应该是其依赖项的父项。您可能希望将该顶级项目作为WAR项目和WAR中依赖项的JAR项目的父项。

That's not really what a top-level project is for. Your WAR project has dependencies, which are the artifacts (e.g. jars) that will be included in the WAR (in WEB-INF/lib) when you run 'mvn package'. Your WAR project pom can have the top-level project as its parent, but it shouldn't be the parent of its dependencies. You may want to have that top-level project be the parent of both the WAR project and of the JAR projects that are dependencies in the WAR.

这篇关于有一个maven项目构建自己的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆