开发者

Maven vs Ant for automatic builds in Android applications

开发者 https://www.devze.com 2023-03-11 09:17 出处:网络
I\'m evaluating whether to use Ant or Maven to automate my build process for Android development. I\'ve been trying to read online to make an informed decision, but haven\'t found many specifics that

I'm evaluating whether to use Ant or Maven to automate my build process for Android development. I've been trying to read online to make an informed decision, but haven't found many specifics that relate to Android development. Based on your experience:

  • What are the main differences ?
  • I've read some people saying they have different purposes ? What would those be ?
  • What would make you pick one over the other 开发者_JAVA百科?
  • What are the strong points and weaknesses of each ?
  • Which is easier to setup and maintain ?
  • Is there one that is proffered/most used in the community ?

I found a similar question What benefits does Maven give (over ant) for building android projects?, but he was asking about the benefits of Maven over Ant and, first, I don't even know the Ant benefits and, second, he just got one answer that didn't make things clear for me.

I use Intellij, just in case it makes any difference though I hope it doesn't.


If you can use Maven, go with Maven. And, don't you dare try to change the standard directories! Heck, even when we use Ant, I insist we setup the directories like Maven. That way, new developers know where things are, or have to trace through the build.xml to find where things are located. The other things is that if you do use Ant, you should also use Ivy. That way, you get the Maven dependency handling within Ant.

The big irony is that once we use Ant and Ivy, and stick to the standard Maven directory structure, moving from Ant to Maven is a cinch. But, the need to move to Maven is lessened too. Our build.xml is clean and simple to understand. All the files are in the right place. Builds are quick, simple, and easy to maintain. Who needs Maven?

The problem is once we've reach this state of Nirvana, is to keep the project from heading back to the State of New Jersey. Developers start carving out exceptions in our build.xml. Don't compile this *.java file. Move this *.xml into our java directory, put test code under the main directory, but we'll put the name test in the file, so we know it's test code... New and complex things are done. And, somehow, we're back in Secaucus.

So, once I've got my Ant project clean and neat enough to move to Maven, I make the leap.

One more thing: Maven makes it very, very simple to copy a project from one computer to another. Maven handles all the dependencies stuff -- even the build stuff. No more, you need AntContrib, or you need to download the hibernate Ant tasks. If you need something, it'll download itself. It's one of the big reasons Maven is so popular with many open source sites.

My big complaint about Maven is that it's so poorly documented. There's a Wiki, but almost no content, and very few manuals.


I've not used Ant or Maven much for Java recently, but I can tell you the main differences between them -- it basically boils down to automated conventions (Maven) vs. absolute flexibility (Ant).

Maven will do almost everything for you, but it's much easier to use if you arrange your projects to suit it. It'll handle dependency tracking and resolution, building, packaging and storing the built packages, while also helping with branch maintenance and release engineering. I find it an awful lot easier to release my (flex) projects that are built with Maven.

Ant is much more flexible. You can do whatever you want, build in whichever way you want. If you have pre-existing projects, you can automate much of what your IDE is doing without changing anything else. It doesn't hand-hold as much as Maven, which also makes it easier to diagnose when things go wrong... You're on your own for dependencies, branches and releases, though. Where we use ant, we use it because we had a project set up which we wanted to automate, and Maven wouldn't adapt to fit it. If you need to do something not supported by Maven, Ant may be your only hope.

Personally, I'd use Maven over Ant if possible, but I'd admit that it's not always possible.


Consider using Gradle!

It combines the best from Maven (convention over configuration) with the best from Ant (the flexibility and the huge library of pre-made tasks).

A Gradle build is written in Groovy, so you have the full power of a scripting language at your fingertips!

There is an Android plugin for Gradle. I haven't used it though, so I cannot tell if it's good or not.

See http://www.gradle.org


I agree with Andrew's answer in its entirety. However, I would note that the maven support is not supplied by the android SDK team. It's provided by a third party. Now, they are an active participant, but it still means that there may be a delay in getting support for the very latest features.

That said, I don't particularly like the ant support provided by the android SDK team. If you run android create project you'll end up with a build.xml that recommends you copy paste chunks of XML in order to customise it. This makes it burdensome to move to a new version of the Android SDK.

Overall, I suspect that moving to maven will be easier to maintain over the long run.

0

精彩评论

暂无评论...
验证码 换一张
取 消