如何将Maven添加到现有的IntelliJ Android项目中

时间:2023-01-17 13:15:54

I've been doing some research on adding Maven to an existing Android project and I'm struggling to see how this works. I've used Maven once at work on a web based project with Netbeans, but for this project I'm looking to use IntelliJ. I can create a new "Maven Module", but I already have an Android project so I'm not entirely sure that's the route I should be taking.

我一直在研究如何将Maven添加到现有的Android项目中,我很难看到它是如何工作的。我曾经在Netbeans的网络项目中使用过Maven,但是对于这个项目,我希望使用IntelliJ。我可以创建一个新的“Maven模块”,但我已经有了一个Android项目,所以我不完全确定这是我应该采取的路线。

I found this post which does provide some detail, but not a step-by-step windows integration guide (at least that I'm seeing).

我发现这篇文章确实提供了一些细节,但不是一步一步的Windows集成指南(至少我看到了)。

Is it possible for me to use Maven within an Android project?

我可以在Android项目中使用Maven吗?

Edit: I'm looking to do this within a Windows environment

编辑:我希望在Windows环境中执行此操作

1 个解决方案

#1


7  

To answer your question in the last sentence: Yes, you can use Maven to build an Android project.

在最后一句中回答你的问题:是的,你可以使用Maven来构建一个Android项目。

You should use the maven-android-plugin in your Maven project. The best place to get started is https://code.google.com/p/maven-android-plugin/wiki/GettingStarted. Need to read up a bit, but definitely worth the effort.

你应该在你的Maven项目中使用maven-android-plugin。入门的最佳位置是https://code.google.com/p/maven-android-plugin/wiki/GettingStarted。需要阅读一下,但绝对值得付出努力。

If I have existing IDE specific Android project that you would like to switch to Maven, instead of trying to "add Maven support to an existing IntelliJ project", I would:

如果我想要切换到Maven的现有IDE特定的Android项目,而不是尝试“将Maven支持添加到现有的IntelliJ项目”,我会:

  1. Create a new Maven based project using an appropriate archetype https://github.com/akquinet/android-archetypes

    使用适当的原型创建一个新的基于Maven的项目https://github.com/akquinet/android-archetypes

  2. Copy existing source/resources to the Maven project directories.

    将现有源/资源复制到Maven项目目录。

If done correctly, you can open this (Android) Maven project (pom.xml) in IntelliJ and use it like an Android project (including GUI editor). IntelliJ automatically generates an IntelliJ project from Maven's pom.xml and detects the Android facet.

如果操作正确,您可以在IntelliJ中打开此(Android)Maven项目(pom.xml)并将其用作Android项目(包括GUI编辑器)。 IntelliJ自动从Maven的pom.xml生成IntelliJ项目并检测Android facet。

This way, your project also stays IDE agnostic - you can do everything (build/test/deploy) from command line as well - how Maven projects should be IMHO. :D

这样,您的项目也保持IDE不可知 - 您也可以从命令行执行所有操作(构建/测试/部署) - Maven项目应该如何恕我直言。 :d

#1


7  

To answer your question in the last sentence: Yes, you can use Maven to build an Android project.

在最后一句中回答你的问题:是的,你可以使用Maven来构建一个Android项目。

You should use the maven-android-plugin in your Maven project. The best place to get started is https://code.google.com/p/maven-android-plugin/wiki/GettingStarted. Need to read up a bit, but definitely worth the effort.

你应该在你的Maven项目中使用maven-android-plugin。入门的最佳位置是https://code.google.com/p/maven-android-plugin/wiki/GettingStarted。需要阅读一下,但绝对值得付出努力。

If I have existing IDE specific Android project that you would like to switch to Maven, instead of trying to "add Maven support to an existing IntelliJ project", I would:

如果我想要切换到Maven的现有IDE特定的Android项目,而不是尝试“将Maven支持添加到现有的IntelliJ项目”,我会:

  1. Create a new Maven based project using an appropriate archetype https://github.com/akquinet/android-archetypes

    使用适当的原型创建一个新的基于Maven的项目https://github.com/akquinet/android-archetypes

  2. Copy existing source/resources to the Maven project directories.

    将现有源/资源复制到Maven项目目录。

If done correctly, you can open this (Android) Maven project (pom.xml) in IntelliJ and use it like an Android project (including GUI editor). IntelliJ automatically generates an IntelliJ project from Maven's pom.xml and detects the Android facet.

如果操作正确,您可以在IntelliJ中打开此(Android)Maven项目(pom.xml)并将其用作Android项目(包括GUI编辑器)。 IntelliJ自动从Maven的pom.xml生成IntelliJ项目并检测Android facet。

This way, your project also stays IDE agnostic - you can do everything (build/test/deploy) from command line as well - how Maven projects should be IMHO. :D

这样,您的项目也保持IDE不可知 - 您也可以从命令行执行所有操作(构建/测试/部署) - Maven项目应该如何恕我直言。 :d