Imperative vs Declarative build systems

前端 未结 1 1860
孤街浪徒
孤街浪徒 2021-01-30 13:30

I have recently started using Gradle as a build system. They first comparison that Gradle makes with the likes of Ant and Maven is that, Ant is an imperative

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 14:05

    In short, an ant script tells the ant tool what to do - "compile these files and then copy them to that folder. Then take the contents of this folder and create an archive."

    While a maven pom declares what we would like to have as the result - "here are the names of the libraries the project depends upon, and we would like to generate a web archive". Maven knows how to fetch the libraries and where to find the source classes on it's own.

    While ant gives you more flexibility, it also forces you to constantly reinvent the wheel.

    Maven on the other side requires less configuration, but may feel too constraining, especially if you are used to a different workflow.

    EDIT: An important aspect of the ant-maven comparison is that maven has a convention, describing where the files should lie, where the dependencies are found, where to put the resulting artifact, while ant does not.

    So you can think of using maven like riding a bus - you select the stop where you enter and the one where you leave. Using ant is like driving a car - you have to do it yourself. You dont have to tell the bus driver what to do, but the stops may be too far from where you want to go.

    EDIT2: 'Reinventing the wheel' metaphor seems to be less clear than I had hoped. This is what I mean:

    Without sensible defaults/conventions, you have to define the project structure and the build lifecycle explicitly for each project, often making it a matter of taste and opinion. As preferences vary between teams and companies, so do build processes. This requires more cognitive effort for new project members and later maintainers. Depending on the experience and expertise of the developers, the final solution may be hard to extend and use.

    As I said in a comment below, while best practices for ant builds exist, they still have to be implemented for each project, or copy-pasted from project to project, instead of becoming an out-of-the-box default of the build tool itself.

    Maven is a bit too far on the other side of the trade-off for my taste. Changing the defaults is not as easy as it could and should be.

    0 讨论(0)
提交回复
热议问题