Java 为什么要结合 Maven 和 Git?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19080093/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:55:59  来源:igfitidea点击:

Why the combination of Maven with Git?

javagitmaven

提问by Kris

I started a job in a company where they use Maven in combination with Git. I haven't worked with Maven before and I hope my question isn't too stupid. Why should one use Maven in combination with Git? From what I read Maven has a local, a central and can have a remote repository where it can find it's dependencies. This should enable a team of programmers to work together on the same code. What is the purpose of Git here? Would it be possible to program in a Team just with Maven and without the help of Git?

我在一家他们将 Maven 与 Git 结合使用的公司开始了一份工作。我之前没有与 Maven 合作过,我希望我的问题不是太愚蠢。为什么要结合使用 Maven 和 Git?从我读到的 Maven 有一个本地的、一个中央的,并且可以有一个远程存储库,它可以在其中找到它的依赖项。这应该使一组程序员能够一起处理相同的代码。Git在这里的目的是什么?是否可以仅使用 Maven 而无需 Git 帮助在团队中进行编程?

采纳答案by hyde

I guess it would be possibleto work with just Maven. It might even not be totally horrible. However, Maven is system for distributing releases(even if they are snapshots or whatever). It is a totally different tool, than what a version control software is. I guess you could say Maven is the just the "distributed" part without the "version control" part of DVCS systems such as git.

我想可以只使用 Maven。它甚至可能并不完全可怕。但是,Maven 是用于分发版本的系统(即使它们是快照或其他)。它是一个完全不同的工具,与版本控制软件不同。我想您可以说 Maven 只是 DVCS 系统(例如 git)中没有“版本控制”部分的“分布式”部分。

A real version control can do a lot of stuffMaven does not support directly, such as merging, diffs, commit logs. I'm sure it would be possibleto build an actual, fully featured version control system on top of Maven, with suitable plugins, but it would be very klunky and awkward to use. The likes of gitalready do all this, and they have been designed to do it from the start, so they do it better than some hack on top of Maven could ever do, so I doubt nobody has actually tried.

真正的版本控制可以做很多Maven 不直接支持的事情,比如合并、差异、提交日志。我确信有可能在 Maven 之上构建一个实际的、功能齐全的版本控制系统,使用合适的插件,但使用起来会非常笨拙和笨拙。喜欢的人git已经做到了这一切,而且他们从一开始就被设计为这样做,所以他们做得比在 Maven 之上的一些 hack 做得更好,所以我怀疑没有人真正尝试过。

I mean, you could do version control with just shared folder, naming conventions, manual log files, an IM group chat (irc channel) for synchronizing between developers, stock diff tools etc for comparing stuff, etc. It would just be horrible to use and very easy to "break" (in this case, easy to corrupt entire project and all its history). There has been a long evolution of version control systems, you can start reading about it for example here, and starting do it on top of Maven would be like jumping 30 years back in time.

我的意思是,您可以仅使用共享文件夹、命名约定、手动日志文件、用于在开发人员之间进行同步的 IM 群聊(irc 频道)、用于比较内容的库存差异工具等来进行版本控制。使用起来会很糟糕并且很容易“破坏”(在这种情况下,很容易破坏整个项目及其所有历史记录)。版本控制系统已经有很长的发展历程,你可以在这里开始阅读它的例子,在 Maven 上开始做它就像回到 30 年前。

回答by TheKojuEffect

When using Maven, your project's dependencies are well defined in pom.xmlwhich is good for collaborative development as addition of dependencies doesn't require other developers to be informed as Mavenautomatically handles dependencies itself by downloading dependencies.

使用 时Maven,您的项目的依赖项已明确定义,pom.xml这有利于协作开发,因为添加依赖项不需要通知其他开发人员,因为Maven通过下载依赖项自动处理依赖项本身。

Git is used for distributed version control which is very good to keep track code changes in your project.

Git 用于分布式版本控制,非常适合跟踪项目中的代码更改。

Basically, these two tools make collaborative development easy. However, this is just a crash course description, there are many of advantages.

基本上,这两个工具使协作开发变得容易。然而,这只是速成课程的描述,有很多优点。

回答by Christian Kuetbach

Well maven and git are for different purposes:

好吧,maven 和 git 用于不同的目的:

  • GITholds the sourcecode of your application

  • MAVENis used for dependency management. It holds the binary dependecies of your application. It also creates a abstraction of the used IDE. One developer can use eclipse and another intellij. The project can also be built with the commandline.

  • GIT保存您的应用程序的源代码

  • MAVEN用于依赖管理。它保存您的应用程序的二进制依赖项。它还创建了所用 IDE 的抽象。一个开发人员可以使用 eclipse 和另一个 intellij。该项目也可以使用命令行构建。