java 从 IntelliJ 调用 Maven 模块构建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2723399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invoke Maven-Module Build from IntelliJ
提问by Roman
I was wondering if someone knows a way to invoke a specific Maven module build from IntelliJ that will also build (or use already compiled classes from) modules on which it depends.
我想知道是否有人知道从 IntelliJ 调用特定 Maven 模块构建的方法,该模块也将构建(或使用已经编译的类)它所依赖的模块。
So for instance if I would like to only build the module "Model" in the picture, it seems reasonable for me to click the package step on it. But what it actually does it invokes the mvn packagestep inside this specific module rather than mvn -am -pl module-namefrom the root module, which also builds all the dependencies.
因此,例如,如果我只想构建图片中的模块“模型”,那么单击其上的包步骤似乎是合理的。但它实际执行的操作是调用mvn package此特定模块内的步骤,而不是mvn -am -pl module-name从根模块调用,后者也构建了所有依赖项。
So is there something that I just don't know?
那么有什么我不知道的吗?
removed dead ImageShack link
删除了无效的 ImageShack 链接
回答by sal
I do it this way (Idea 8.1.4)
我这样做(想法8.1.4)
- Open run dialog (shift-f10 on windows)
- Click +and pick Mavento add a Maven build config
- Fill in the form, adding
- 1 working directory
- 2 maven command line options
- 3 maven goals
- 4 profiles
- 打开运行对话框(windows 上的 shift-f10)
- 单击+并选择Maven以添加 Maven 构建配置
- 填写表格,添加
- 1 个工作目录
- 2 Maven 命令行选项
- 3个Maven目标
- 4 个人资料
This is no different than running from command line. Which is what I am assuming you want.
这与从命令行运行没有什么不同。这就是我假设你想要的。
回答by mdma
You know the mvn command line well! To put this command line into IDEA, right click on your root project, one of the options will be "Create ... [package]".
你很了解 mvn 命令行!要将此命令行放入 IDEA,请右键单击您的根项目,其中一个选项是“Create ... [package]”。
Make these edits:
进行这些编辑:
- set the name to something like "Make Model [install]"
- In the goals box, enter your command line, i.e. "-am -pl model install"
- 将名称设置为“Make Model [install]”
- 在目标框中,输入您的命令行,即“-am -pl model install”
I know these aren't strictly goals, but it seems they are passed directly to maven. (Tested in IDEA 9.0.1)
我知道这些并不是严格的目标,但似乎它们直接传递给了 maven。(在 IDEA 9.0.1 中测试)
When you run this command, it will now make Model - and the modules it depends on. Equally useful is the "-amd" to make all dependent moduels to verify that changes to Model haven't broken other modules. Having to create Run commands is not quite as elegant as the built-in UI, but you can associate these commands with hotkeys for quick access.
当您运行此命令时,它现在将生成模型 - 以及它所依赖的模块。同样有用的是“-amd”让所有依赖模块验证对模型的更改没有破坏其他模块。必须创建运行命令并不像内置 UI 那样优雅,但您可以将这些命令与热键关联以便快速访问。
Hope this helps! mdma
希望这可以帮助!mdma
PS: A small aside. Package is currently your default build goal - this may not work as intended with multi-module builds, since the latest built classes are not accessible to dependent modules - using install as the default goal is recommended to ensure the most recently built versions of artefacts are used by dependents. If you're concerned that installing might add a broken artefact to the local repo and break all your local builds, use a separate local repo for each project (use a custom settings.xml.)
PS:一小部分。包当前是您的默认构建目标 - 这可能无法在多模块构建中按预期工作,因为依赖模块无法访问最新构建的类 - 建议使用 install 作为默认目标,以确保最新构建的工件版本是供养人使用。如果您担心安装可能会向本地存储库添加损坏的人工制品并破坏所有本地构建,请为每个项目使用单独的本地存储库(使用自定义 settings.xml。)

