# Chapter 5. Artifact Basics

This chapter is currently under construction.

For all the details of artifact handling see Chapter 26, Artifact Management.

This chapter introduces some of the basics of artifact handling in Gradle.

## 5.1. Artifact configurations

Artifacts are grouped into configurations. A configuration is simply a set of files with a name. You can use them to declare the external dependencies your project has, or to declare the artifacts which your project publishes.

To define a configuration:

Example 5.1. Definition of a configuration

`build.gradle`

    configurations {
        compile
    }

To access a configuration:

Example 5.2. Accessing a configuration

`build.gradle`

    println configurations.compile.name
    println configurations['compile'].name

To configure a configuration:

Example 5.3. Configuration of a configuration

`build.gradle`

    configurations {
        compile {
            description = 'compile classpath'
            transitive = true
        }
        runtime {
            extendsFrom compile
        }
    }
    configurations.compile {
        description = 'compile classpath'
    }

## 5.2. Repositories

Artifacts are stored in repositories.

To use maven central repository:

Example 5.4. Usage of Maven central repository

`build.gradle`

    repositories {
        mavenCentral()
    }

To use a local directory:

Example 5.5. Usage of a local directory

`build.gradle`

    repositories {
        flatDir name: 'localRepository', dirs: 'lib'
    }

You can also use any Ivy resolver. You can have multiple repositories.

To access a repository:

Example 5.6. Accessing a repository

`build.gradle`

    println repositories.localRepository.name
        println repositories['localRepository'].name

To configure a repository:

Example 5.7. Configuration of a repository

`build.gradle`

    repositories {
        localRepository {
            addArtifactPattern(file('lib').absolutePath + '/[name]/[revision]/[name]-[revision].[ext]')
        }
    }
    repositories.localRepository {
        addArtifactPattern(file('lib').absolutePath + '/[name]/[revision]/[name]-[revision].[ext]')
    }

## 5.3. External dependencies

To define an external dependency, you add a dependency to a configuration:

Example 5.8. Definition of an external dependency

`build.gradle`

    configurations {
        compile
    }

    dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    }

`group` and `version` are optional

TBD - configuring an external dependency

To use the external dependencies of a configuration:

Example 5.9. Usage of external dependency of a configuration

`build.gradle`

    task listJars << {
        configurations.compile.each { File file -> println file.name }
    }

Output of `gradle -q listJars`

    > gradle -q listJars
    commons-collections-3.2.jar

## 5.4. Artifact publishing

TBD

## 5.5. API

Configurations are contained in a `ConfigurationContainer` . Each configuration implements the `Configuration` .