Reputation: 5542
Example in the gradle war plugin: why need to define moreLibs like the following? please explain:
configurations {
moreLibs
}
dependencies {
moreLibs ":otherLib:1.0"
}
war {
classpath configurations.moreLibs
webXml = file('src/someWeb.xml')
}
Can we define anything inside configurations?
configurations {
foobar
}
I have seen these in many places. Can anyone explain?
Upvotes: 6
Views: 9098
Reputation: 38619
Yes, you can write anything in the configurations block and it will create a new configuration with that name and you can also further configure it, e. g. by setting its transitive
property to false
and other stuff.
A custom configuration is just a name for which you can define dependencies that are then resolved transitively by Gradle automatically and can be used for various purposes where you need those resolved files.
In your example you define a moreLibs
configuration, add a dependency to it that will be resolved transitively by Gradle and then added to the wars lib
directory.
You don't have to do this if you don't have a need to. All libs in the runtime
configuration (and thus also those in the compile
configuration) are automatically added to the wars lib
directory. But if you for some reason need additional libs in there that you don't want to add to compile
or runtime
, you can do it this way.
Another example of where a custom configuration can be useful is if you want to use a custom Ant task. You define a custom configuration, add the Ant tasks dependency to it, then you let Gradle transitively resolve it and can add the whole fileset as classpath to the taskdef for Ant.
Upvotes: 5