23

When I run the "dependencies" task there are several sections: compile, runtime, testCompile ...

One of those sections is "default - Configuration for default artifacts." What is this section and what is it used for?

How do I change what is in the "default configuration"?

Details: Gradle 1.7

Rylander
  • 19,449
  • 25
  • 93
  • 144

3 Answers3

31

Unless your build is publishing Ivy modules, the default configuration is mainly relevant when dealing with project dependencies in a multi-project build. Given a multi-project build with projects A and B, if A declares a project dependency on B without explicitly naming a configuration (e.g. dependencies { compile project(":B") }, A (more precisely A's compile configuration) will depend on project B's default configuration. In other words, dependencies { compile project(":B") } is a shortcut for dependencies { compile project(path: ":B", configuration: "default") }.

The default configuration extends from the runtime configuration, which means that it contains all the dependencies and artifacts of the runtime configuration, and potentially more. You can add dependencies and artifacts in the usual way (using a dependencies/artifacts block in B's build script). Alternatively, B could declare a custom configuration, and A could depend on that by explicitly naming that configuration (e.g. dependencies { compile project(path: ":B", configuration: "myCustomConfig") }.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
5

When using the gradle java plugin the 'default' configuration extendsFrom 'runtime', 'runtimeOnly', 'implementation'

If you do not use the java plugin then you can define it yourself like this

configurations {
    "default"
}

The java plugin sets up the default configuration here: https://github.com/gradle/gradle/blob/85d30969f4672bb2739550b4de784910a6810b7a/subprojects/plugins/src/main/java/org/gradle/api/plugins/JavaPlugin.java#L437

The documentation is not that good in this area.

An example of "serving" a default artifact from a composite build. The example creates a subproject that refers to a dependency in another project. This can be nessesary when working with composite builds, as only the "default" group can be depended upon.

We use this to take many jars from a single project and serve it as different dependencies when referencing the project as a composite build.

apply plugin: 'base'

configurations {
    depend
}

dependencies {
    depend project(path: ':', configuration: 'ConfWithArtifact')
}

artifacts {
    "default" (file: configurations.depend.singleFile) {
        builtBy(configurations.depend)
    }
}
Jesper
  • 111
  • 2
  • 6
0

The default configuration is actually created by the base plugin, and so you don't need to define it yourself.

I've also had the problem with composite builds only compositing from the default configuration, but I solved it slightly differently:

plugins {
    id 'base'
}

configurations {
    bootstrap
    it.'default'.extendsFrom bootstrap
}

dependencies {
    bootstrap project(path: ':other', configuration: 'otherConfiguration')
}

This approach allows the artifact from the :other project to keep its transitive dependencies, assuming you're interested in keeping them.

Chris Rankin
  • 256
  • 1
  • 3
  • 10