Structure of Projects in Version Control

12,068

Solution 1

We practice highly componentised development using Java, we have about 250 modules in trunk that have independent life cycles. Dependencies are managed through Maven (that's a best practice right there), every iteration (bi-weekly) actively developed modules get tagged with a new version. 3 digit version numbers with strict semantics (major.minor.build - major changes means backwards incompatible, minor changes mean backwards compatible and build number changes mean backwards and forwards compatible). Our ultimate software product is an assembly that pulls in dozens of individual modules, again as Maven dependencies.

We branch modules/assemblies when we need to make a bug fix or enhancement for a released version and we can not deliver the HEAD version. Having tagged all versions makes this easy to do but branches still incur a significant administrative overhead (specifically keeping branches in sync with certain HEAD changesets) that are partly caused by our tools, Subversion is sub-optimal for managing branches.

We find that a fairly flat and above all predictable tree structure in the repository is crucial. It has allowed us to build release tools that take away a lot of the pain and danger from a manual release process (updated release notes, project compiles, unit tests run through, tag is made, no SNAPSHOT dependencies, etc). Avoid putting too much categorization or other logic in your tree structure.

We roughly do something like the following:

svnrepo/
  trunk/
    modules/
      m1/ --> will result in jar file
      m2/
      ...
    assemblies/
      a1/
      ...
  tags/
    modules/
      m1/
        1.0.0/
        1.0.1/
        1.1.0/
       m2/
      ...
    assemblies/
      a1/
        iteration-55/
        ...
  branches/
    m1/
      1.0/
      ...

For external dependencies, I can not overemphasize something like Maven: manage your dependencies as references to versioned, uniquely identified binary artifacts in a repository.

For intenal module/project structure: stick to a standard. Uniformity is key. Again, Maven can help here since it dictates a structure. Many structures are fine, as long as you stick to them.

Solution 2

Example for SVN:

trunk/

branch/

tags/

The trunk should be kept at a point where you can always push a release from it. There should be no huge gaping bugs that you know about(of course there will be eventually but that is what you should strive for).

Every time you need to make a new feature, do a design change, whatever, branch. Tag that branch at the start. Then when you are finished with the branch tag it at the end. This helps out with merging back into trunk.

Every time you need to push a release, tag. This way if something goes horribly wrong you can rollback to the previous release.

This setup keeps trunk as clean as possible and allows you to make quick bug fixes and push them out while keeping the majority of your development in branches.

Edit: For 3rd party stuff it depends. If I can avoid it I do not have it under source control. I keep it in a directory outside source control and include it from there. For things like jquery, I do leave it under source control. The reason is it simplifies my script for pushing. I can simply have it do an svn export and rsync.

Solution 3

For my projects, I always use this structure.

  • trunk
    • config
    • docs
    • sql
      • initial
      • updates
    • src
      • app
      • test
    • thirdparty
      • lib
      • tools
  • tags
  • branches
  • config - Used to store my application config templates. During the build process, I take these templates and replace token placeholders with actual values depending on what configuration I am making the build.
  • docs - Any application documentation gets placed in here.
  • sql - I break my sql scripts into two directories. One for the initial database setup for when you are starting fresh and another place for my update scripts which get ran based on the version number of the database.
  • src - The application source files. In here I break source files based on application and tests.
  • thirdparty - This is where I put my third party libraries that I reference inside of my application and not available in the GAC. I split these up based on lib and tools. The lib directory holds the libraries that need to be included with the actual application. The tools directory holds the libraries that my application references, but are only used for running unit tests and compiling the application.

My solution file gets placed right under the trunk directory along with my build files.

Solution 4

I can appreciate the logic of not putting binaries in the repository but I think there is a huge advantage too. If you want to be able to pull a specific revision out from the past (usually an older tag) I like being able to have everything I need come from the svn checkout. Of course this doesn't include Visual Studio or the .NET framework but having the right version of nant, nunit, log4net, etc. makes it really easy to go from checkout to build. This way getting started is as easy as "svn co project" followed by "nant build".

One thing we do is put ThirdParty binaries in a separate tree and use svn:external to bring it the version we need. To make life easy, we'll have a folder for each version that has been used. For example, we might bring in the ThirdParty/Castle/v1.0.3 folder to the current project. This way everything need to build/test the product is inside or below the project root. The tradeoff in disk space is well worth it in our experience.

Solution 5

As we have all the artifacts and construction in the same tree we have something like:

  • Trunk

    • Planning&Tracking
    • Req
    • Design
    • Construction
      • Bin
      • Database
      • Lib
      • Source
  • Deploy

  • QA
  • MA
Share:
12,068
oglester
Author by

oglester

Believer, husband, dad, & developer. I enjoy occasionally answering some questions on here and of course find many good answers.

Updated on June 19, 2022

Comments

  • oglester
    oglester almost 2 years

    I know there are at least 10 different ways to structure project in version control. I'm curious what some methods being used are and which ones work for you. I've worked with SVN, TFS, and currently/unfortunately VSS. I've seen version control implemented very poorly and just OK, but never great.

    Just to get the ball rolling, here is a review of things I've seen.

    This example is SVN-based, but applies to most VCS's (not so much to distributed version control).

    1. branch the individual projects that are part of site /division/web/projectName/vb/src/[trunk|branches|tags]

    2. branch the whole site, in the case I've seen, the whole site except for core components was branched. /division/[trunk|branches|tags]/web/projectName/vb/src/

    3. Use main-line a default, only branch when necessary for huge changes.

  • whaley
    whaley almost 15 years
    Is there something like maven that even exists for .NET? I've been unable to unearth anything.
  • aberrant80
    aberrant80 almost 15 years
    It looks like a good start that we're kicking off a new project with a structure similar to yours :) Out of curiosity, do you have a shared parent pom? If so, do you place the parent pom in the "modules" directory or as an actual directory inside "modules"?
  • Boris Terzic
    Boris Terzic almost 15 years
    We have a hierarchy of parent poms and we treat them just like we do modules: they each have their own "module" directory inside modules. Since Maven2 this is finally cleanly possible since the parent poms are inherited over the repository. In Maven1 you actually have to use relative paths and it becomes nasty.
  • aberrant80
    aberrant80 almost 15 years
    Thank you :D Just one more question if you don't mind. We've had to do some module-renaming right now (inappropriate initial names), and we have a little argument going on. If, say, your "trunk/modules/m1" needs to be renamed to "trunk/modules/m10", do you think "tags/modules/m1" should be renamed to "tags/modules/m10" or should "tags/modules/m1" be retained and a new "tags/modules/m10" be created?
  • Boris Terzic
    Boris Terzic almost 15 years
    Considering that you tag so that the build is reproducible and given that if you tagged you probably have already released artifacts with the "old" name, I would create a new "m10" tag folder next to the old one. In our case, the old modules would otherwise have artifactIds that are different from their module directory names and that would be non-intuitive.
  • Nathan Palmer
    Nathan Palmer over 14 years
    Why was this marked down? Seems like a decent structure even if it isn't one of the standard versions you see.
  • wal
    wal over 12 years
    how do you branch? if you branch just the src folder how do you handle your branch pointing to an older version of a thirdparty/lib?
  • Greg Domjan
    Greg Domjan almost 12 years
    Just a note, NMaven was retired and NPanday is the new name still in incubator.
  • hhh
    hhh almost 12 years
    Skeptical thread whether Maven is just clutter, more here.
  • FvD
    FvD almost 11 years
    Could you please update the link to the diagram in first paragraph?