[[dependency_types]]
== Dependency Types

[[sub:module_dependencies]]
=== Module dependencies

Module dependencies are the most common dependencies. They refer to a module in a repository.

++++
<sample id="moduleDependencies" dir="userguide/artifacts/externalDependencies" title="Module dependencies">
    <sourcefile file="build.gradle" snippet="module-dependencies"/>
</sample>
++++

See the api:org.gradle.api.artifacts.dsl.DependencyHandler[] class in the API documentation for more examples and a complete reference.

Gradle provides different notations for module dependencies. There is a string notation and a map notation. A module dependency has an API which allows further configuration. Have a look at api:org.gradle.api.artifacts.ExternalModuleDependency[] to learn all about the API. This API provides properties and configuration methods. Via the string notation you can define a subset of the properties. With the map notation you can define all properties. To have access to the complete API, either with the map or with the string notation, you can assign a single dependency to a configuration together with a closure.

[NOTE]
====
If you declare a module dependency, Gradle looks for a module metadata file (`.module`, `.pom` or `ivy.xml`) in the repositories. If such a module metadata file exists, it is parsed and the artifacts of this module (e.g. `hibernate-3.0.5.jar`) as well as its dependencies (e.g. cglib) are downloaded. If no such module metadata file exists, Gradle may look, depending on the <<sub:supported_metadata_sources,metadata sources definitions>>, for an artifact file called `hibernate-3.0.5.jar` directly. In Maven, a module can have one and only one artifact. In Gradle and Ivy, a module can have multiple artifacts. Each artifact can have a different set of dependencies.
====

[[sub:file_dependencies]]
=== File dependencies

File dependencies allow you to directly add a set of files to a configuration, without first adding them to a repository. This can be useful if you cannot, or do not want to, place certain files in a repository. Or if you do not want to use any repositories at all for storing your dependencies.

To add some files as a dependency for a configuration, you simply pass a <<sec:file_collections,file collection>> as a dependency:

++++
<sample id="file-dependencies" dir="userguide/artifacts/externalDependencies" title="File dependencies">
    <sourcefile file="build.gradle" snippet="file-dependencies"/>
</sample>
++++

File dependencies are not included in the published dependency descriptor for your project. However, file dependencies are included in transitive project dependencies within the same build. This means they cannot be used outside the current build, but they can be used with the same build.

You can declare which tasks produce the files for a file dependency. You might do this when, for example, the files are generated by the build.

++++
<sample id="generatedFileDependencies" dir="userguide/artifacts/generatedFileDependencies" title="Generated file dependencies">
    <sourcefile file="build.gradle" snippet="generated-file-dependencies"/>
    <output args="-q list"/>
</sample>
++++

[[sub:project_dependencies]]
=== Project dependencies

Gradle distinguishes between external dependencies and dependencies on projects which are part of the same multi-project build. For the latter you can declare _project dependencies_.

++++
<sample id="project-dependencies" dir="java/multiproject/api" title="Project dependencies">
    <sourcefile file="build.gradle" snippet="project-dependencies"/>
</sample>
++++

For more information see the API documentation for api:org.gradle.api.artifacts.ProjectDependency[].

Multi-project builds are discussed in <<multi_project_builds>>.

[[sub:gradle_distribution_dependencies]]
=== Gradle distribution-specific dependencies

[[sub:api_dependencies]]
==== Gradle API dependency

You can declare a dependency on the API of the current version of Gradle by using the api:org.gradle.api.artifacts.dsl.DependencyHandler#gradleApi[] method. This is useful when you are developing custom Gradle tasks or plugins.

++++
<sample id="gradle-api-dependencies" dir="customPlugin/plugin" title="Gradle API dependencies">
    <sourcefile file="build.gradle" snippet="gradle-api-dependencies"/>
</sample>
++++

[[sub:testkit_dependencies]]
==== Gradle TestKit dependency

You can declare a dependency on the TestKit API of the current version of Gradle by using the api:org.gradle.api.artifacts.dsl.DependencyHandler#gradleTestKit[] method. This is useful for writing and executing functional tests for Gradle plugins and build scripts.

++++
<sample id="gradle-testkit-dependencies" dir="testKit/gradleRunner/junitQuickstart" title="Gradle TestKit dependencies">
    <sourcefile file="build.gradle" snippet="declare-gradle-testkit-dependency"/>
</sample>
++++

<<test_kit>> explains the use of TestKit by example.

[[sub:groovy_dependencies]]
==== Local Groovy dependency

You can declare a dependency on the Groovy that is distributed with Gradle by using the api:org.gradle.api.artifacts.dsl.DependencyHandler#localGroovy[] method. This is useful when you are developing custom Gradle tasks or plugins in Groovy.

++++
<sample id="local-groovy-dependencies" dir="customPlugin/plugin" title="Gradle's Groovy dependencies">
    <sourcefile file="build.gradle" snippet="local-groovy-dependencies"/>
</sample>
++++
