Skip to content
This repository was archived by the owner on Oct 3, 2019. It is now read-only.

dependency_management

John Shahid edited this page Feb 6, 2011 · 6 revisions

Dependency management

Maven dependency mechanism

One of the goals of the plugin is to implement maven's dependency mechanism. Briefly:

  1. Compile dependencies are added to the runtime/test classpath
  2. Runtime dependencies are added to the test classpath
  3. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's.
  4. Transitive dependency depends on the scope of the dependency. Each of the scopes (except for import) affects transitive dependencies in different ways, as is demonstrated in the table below. If a dependency is set to the scope in the left column, transitive dependencies of that dependency with the scope across the top row will result in a dependency in the main project with the scope listed at the intersection.
compile provided runtime test
compile compile - runtime -
provided provided - provided -
runtime runtime - runtime -
test test - test -

Adding transitive dependency resolution

To add transitive dependencies of compile dependencies to the project (according to rules given in the previous sections) add the following to the project definition.

  project.transitive_scopes = [:compile]

The available scopes are :run, :compile and :test

Nearest definition in action

Assuming that foo:bar:jar:1.1 depends on foo:foobar:jar:1.1

require 'buildr-dependency-extensions'

repositories.remote << "http://www.ibiblio.org/maven2/"

define 'foo-bar' do
  extend TransitiveDependencies

  # define the project-version
  project.version = '1.0.0'

  project.transitive_scopes = [:compile, :run]

  run.with artifact('foo:bar:jar:1.1')
  run.with artifact('foo:foobar:jar:1.0')
end

In this example the runtime dependencies will be foo:bar:jar:1.1 and foo:foobar:jar:1.0

Adding dependency exclusion

Assuming that foo:bar:jar:1.1 depends on foo:foobar:jar:1.0

require 'buildr-dependency-extensions'

repositories.remote << "http://www.ibiblio.org/maven2/"

define 'foo-bar' do
  extend TransitiveDependencies

  # define the project-version
  project.version = '1.0.0'

  project.transitive_scopes = [:compile, :run]

  run.with artifact('foo:bar:jar:1.1').excludes(artifact('foo:foobar:jar:1.0'))
end

In this example the runtime dependencies will be foo:bar:jar:1.1

Caching dependencies

If the extension is taking too long to load the dependency tree, you can enable dependency caching like this:

define 'foo-bar' do
  extend TransitiveDependencies

  # define the project-version
  project.version = '1.0.0'

  project.transitive_scopes = [:compile, :run]
  project.cache_dependencies = true

  run.with artifact('foo:bar:jar:1.1')
end

This will generate a file called dependency.cache. This is a yaml file that has the compile, runtime and test dependencies after adding the transitive dependencies. If transitive dependencies is disabled for some scope, then the dependency cache will only have the declared dependencies that were added in the buildfile. Furthermore, the dependency cache is never updated, if you want to update your cache, remove dependency.cache and rerun buildr. Also if you manually edited the cache, the new dependencies will take effect the next time you run buildr.

Limitations

  1. There is no way to added dependencies with 'provide' scope
  2. Buildr will add compile dependencies to test dependencies, then it adds test dependencies to runtime depencies ! So expect some test dependencies to leak into your project's runtime dependencies.

Clone this wiki locally