English 中文(简体)
Arguments for and against including 3rd-party libraries in version control? [closed]
原标题:
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

I ve met quite a few people lately who says that 3rd party libraries doesn t belong in version control. These people haven t been able to explain to me why they shouldn t yet, so I hoped you guys could come to my rescue :)

Personally, I think that when I check the trunk of a project out, it should just work - No need to go to other sites to find libraries. More often than not, you d end up with multiple versions of the same 3rd party lib for different developers then - and sometimes with incompatibility problems.

Is it so bad to have a libs folder up there, with "guarenteed-to-work" libraries you could reference?

最佳回答

In SVN, there is a pattern used to store third-party libraries called vendor branches. This same idea would work for any other SVN-like version control system. The basic idea is that you include the third-party source in its own branch and then copy that branch into your main tree so that you can easily apply new versions over your local customizations. It also cleanly keeps things separate. IMHO, it s wrong to directly include the third-party stuff in your tree, but a vendor branch strikes a nice balance.

问题回答

Yes you should (when feasible).

You should be able to take a fresh machine and build your project with as few steps as possible. For me, it s:

  1. Install IDE (e.g. Visual Studio)
  2. Install VCS (e.g. SVN)
  3. Checkout
  4. Build

Anything more has to have very good justification.

Here s an example: I have a project that uses Yahoo s YUI compressor to minify JS and CSS. The YUI .jar files go in source control into a tools directory alongside the project. The Java runtime however, does not--that has become a prereq for the project much like the IDE. Considering how popular JRE is, it seems like a reasonable requirement.

Another reason to check in libraries to your source control which I haven t seen mentioned here is that it gives you the ability to rebuild your application from a specific snapshot or version. This allows you to recreate the exact version that someone may report a bug on. If you can t rebuild the exact version you risk not being able to reproduce/debug problems.

No - I don t think you should put third party libraries into source control. The clue is in the name source control .

Although source control can be used for distribution and deployment, that is not its prime function. And the arguments that you should just be able to check out your project and have it work are not realistic. There are always dependencies. In a web project, they might be Apache, MySQL, the programming runtime itself, say Python 2.6. You wouldn t pile all those into your code repository.

Extra code libraries are just the same. Rather than include them in source control for easy of deployment, create a deployment/distribution mechanism that allows all dependencies to easily be obtained and installed. This makes the steps for checking out and running your software something like:

  • Install VCS
  • Sync code
  • Run setup script (which downloads and installs the correct version of all dependencies)

To give a specific example (and I realise this is quite web centric), a Python web application might contain a requirements.txt file which reads:

simplejson==1.2
django==1.0
otherlibrary==0.9

Run that through pip and the job is done. Then when you want to upgrade to use Django 1.1 you simply change the version number in your requirements file and re-run the setup.

The source of 3rd party software doesn t belong (except maybe as static reference), but the compiled binary do.

If your build process will compile an assembly/dll/jar/module, then only keep the 3rd party source code in source control.

If you won t compile it, then put the binary assembly/dll/jar/module into source control.

This could depend on the language and/or environment you have, but for projects I work on I place no libraries (jar files) in source control. It helps to be using a tool such as Maven which fetches the necessary libraries for you. (Each project maintains a list of required jars, Maven automatically fetches them from a common repository - http://repo1.maven.org/maven2/)

That being said, if you re not using Maven or some other means of managing and automatically fetching the necessary libraries, by all means check them into your version control system. When in doubt, be practical about it.

The way I ve tended to handle this in the past is to take a pre-compiled version of 3rd party libraries and check that in to version control, along with header files. Instead of checking the source code itself into version control, we archive it off into a defined location (server hard drive).

This kind of gives you the best of both worlds: a 1 step fetch process that fetches everything you need, but it doesn t bog down your version control system with a bunch of necessary files. Also, by fetching pre-compiled binaries, you can skip that phase of compilation, which makes your builds faster.

You should definitively put 3rd party libraries under the source control. Also, you should try to avoid relying on stuff installed on individual developer s machine. Here s why:

  • All developers will then share the same version of the component. This is very important.
  • Your build environment will become much more portable. Just install source control client on a fresh machine, download your repository, build and that s it (in theory, at least :) ).
  • Sometimes it is difficult to obtain an old version of some library. Keeping them under your source control makes sure you won t have such problems.

However, you don t need to add 3rd party source code in your repository if you don t plan to change the code. I tend just to add binaries, but I make sure only these libraries are referenced in our code (and not the ones from Windows GAC, for example).

We do because we want to have tested an updated version of the vendor branch before we integrate it with our code. We commit changes to this when testing new versions. We have the philosophy that everything you need to run the application should be in SVN so that

  1. You can get new developers up and running
  2. Everyone uses the same versions of various libraries
  3. We can know exactly what code was current at a given point in time, including third party libraries.

No, it isn t a war crime to have third-party code in your repository, but I find that to upset my sense of aesthetics. Many people here seem to be of the opinion that it s good to have your whole developement team on the same version of these dependencies; I say it is a liability. You end up dependent on a specific version of that dependency, where it is a lot harder to use a different version later. I prefer a heterogenous development environment - it forces you to decouple your code from the specific versions of dependencies.

IMHO the right place to keep the dependencies is on your tape backups, and in your escrow deposit, if you have one. If your specific project requires it (and projects are not all the same in this respect), then also keep a document under your version control system that links to these specific versions.

I like to check 3rd party binaries into a "lib" directory that contains any external dependencies. After all, you want to keep track of specific versions of those libraries right?

When I compile the binaries myself, I often check in a zipped up copy of the code along side the binaries. That makes it clear that the code is not there for compiling, manipulating, etc. I almost never need to go back and reference the zipped code, but a couple times it has been helpful.

If I can get away with it, I keep them out of my version control and out of my file system. The best case of this is jQuery where I ll use Google s AJAX Library and load it from there:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>

My next choice would be to use something like Git Submodules. And if neither of those suffice, they ll end up in version control, but at that point, its only as up to date as you are...





相关问题
Tracking Versions, Builds, Revisions, with TortiseSVN

I am the sole developer on a project and have been using tortoiseSVN for quite a while. Now Id like to start getting version information working correctly in the project I.E. show Major Version, Minor ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

How to handle different csproj [closed]

I am working in a team of five. We are working on a C# application with five csprojects. The problem is that for each csproject, each of my colleagues has their own ideas on how to reference a DLL; ...

Changing username in SVN+SSH URI on the fly in working copy

I am using SVN+SSH to check out a working copy of repository from an SVN server on which all developers are members of a developer group and have full read/write permissions on the repository ...

How to search for file in subversion server?

Is there a way to search for a file in a subversion repository? Something similar to Unix find command, with which I can find the location of a file in a repository. I know there is svn list, but ...

热门标签