简体   繁体   English

在Github中包含.jar文件以保持一致性

[英]Including .jar files in Github for consistency

I am new to using github and have been trying to figure out this question by looking at other people's repositories, but I cannot figure it out. 我是新手使用github并一直试图通过查看其他人的存储库来弄清楚这个问题,但我无法弄明白。 When people fork/clone repositories in github to their local computers to develop on the project, is it expected that the cloned project is complete (ie. it has all of the files that it needs to run properly). 当人们将github中的存储库分叉/克隆到他们的本地计算机以在项目上进行开发时,是否期望克隆的项目是完整的(即,它具有正确运行所需的所有文件)。 For example, if I were to use a third-party library in the form of a .jar file, should I include that .jar file in the repository so that my code is ready to run when someone clones it, or is it better to just make a note that you are using such-and-such third-party libraries and the user will need to download those libraries elsewhere before they begin work. 例如,如果我以.jar文件的形式使用第三方库,我是否应该在存储库中包含该.jar文件,以便我的代码可以在有人克隆时运行,或者更好只是记下你正在使用这样的第三方库,用户需要在开始工作之前将这些库下载到其他地方。 I am just trying to figure at the best practices for my code commits. 我只想弄清楚我的代码提交的最佳实践。

Thanks! 谢谢!

Basically it is as Chris said. 基本上就像克里斯说的那样。

You should use a build system that has a package manager. 您应该使用具有包管理器的构建系统。 This way you specify which dependencies you need and it downloads them automatically. 这样,您可以指定所需的依赖项,并自动下载它们。 Personally I have worked with maven and ant. 我个人与maven和蚂蚁合作过。 So, here is my experience: 所以,这是我的经验:

Apache Maven: Apache Maven:

First word about maven, it is not a package manager. 关于maven的第一个词,它不是包经理。 It is a build system. 它是一个构建系统。 It just includes a package manager, because for java folks downloading the dependencies is part of the build process. 它只包含一个包管理器,因为对于java人来说,下载依赖项是构建过程的一部分。

Maven comes with a nice set of defaults. Maven提供了一组很好的默认设置。 This means you just use the archtype plugin to create a project ("mvn archetype:create" on the cli). 这意味着您只需使用archtype插件来创建项目(cli上的“mvn archetype:create”)。 Think of an archetype as a template for your project. 将原型视为项目的模板。 You can choose what ever archetype suits your needs best. 您可以选择最适合您需求的原型。 In case you use some framework, there is probably an archetype for it. 如果您使用某个框架,可能会有一个原型。 Otherwise the simple-project archetype will be your choice. 否则,简单项目原型将是您的选择。 Afterwards your code goes to src/main/java, your test cases go to src/test/java and "mvn install" will build everything. 之后您的代码转到src / main / java,您的测试用例转到src / test / java,“mvn install”将构建所有内容。 Dependencies can be added to the pom in maven's dependency format. 依赖关系可以以maven的依赖关系格式添加到pom中。 http://search.maven.org/ is the place to look for dependencies. http://search.maven.org/是寻找依赖关系的地方。 If you find it there, you can simply copy the xml snippet to your pom.xml (which has been created by maven's archetype system for you). 如果你在那里找到它,你可以简单地将xml片段复制到你的pom.xml(由maven的原型系统为你创建)。

In my experience, maven is the fastest way to get a project with dependencies and test execution set up. 根据我的经验,maven是获得具有依赖关系和测试执行设置的项目的最快方法。 Also I never experienced that a maven build which worked on my machine failed somewhere else (except for computers which had year-old java versions). 此外,我从来没有经历过在我的机器上工作的maven构建在其他地方失败(除了具有一年历史的Java版本的计算机)。 The charm is that maven's default lifecycle (or build cycle) covers all your needs. 魅力在于maven的默认生命周期(或构建周期)涵盖了您的所有需求。 Also there are a lot of plugins for almost everything. 几乎所有东西都有很多插件。 However, you have a big problem if you want to do something that is not covered by maven's lifecycle. 但是,如果你想做一些maven生命周期未涵盖的事情,你就会遇到大问题。 However, I only ever encountered that in mixed-language projects. 但是,我只在混合语言项目中遇到过这种情况。 As soon as you need anything but java, you're screwed. 一旦你需要除了java之外的任何东西,你就会被搞砸了。

Apache Ivy: Apache常春藤:

I've only ever used it together with Apache Ant. 我只和Apache Ant一起使用它。 However, Ivy is a package manager, ant provides a build system. 但是,Ivy是一个包管理器,ant提供了一个构建系统。 Ivy is integrated into ant as a plugin. Ivy作为插件集成到ant中。 While maven usually works out of the box, Ant requires you to write your build file manually. 虽然maven通常可以开箱即用,但Ant要求您手动编写构建文件。 This allows for greater flexibility than maven, but comes with the prize of yet another file to write and maintain. 这允许比maven更大的灵活性,但是还有另一个要编写和维护的文件的奖励。 Basically Ant files are as complicated as any source code, which means you should comment and document them. 基本上Ant文件与任何源代码一样复杂,这意味着您应该对它们进行注释和记录。 Otherwise you will not be able to maintain your build process later on. 否则,您将无法在以后维护构建过程。

Ivy itself is as easy as maven's dependency system. Ivy本身就像maven的依赖系统一样容易。 You have an xml file which defines your dependencies. 您有一个定义依赖项的xml文件。 As for maven, you can find the appropriate xml snippets on maven central http://search.maven.org/ . 至于maven,你可以在maven中心http://search.maven.org/上找到合适的xml片段。

As a summary, I recommend Maven in case you have a simple Java Project. 总结一下,如果你有一个简单的Java项目,我推荐使用Maven。 Ant is for cases where you need to do something special in your build. Ant适用于需要在构建中执行特殊操作的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM