How to explain the concept of Configuration?

What is the configuration ?
Im confused about the difference between configuration and dependencies…
Can someone help me with that?

Configuration represent a classpath. Every time Java loads a class, the JVM consults a classpath for a list of locations where that class may possibly be. Configurations are different from classpaths, because they do not necessarily list files and dirs, but provide instructions how to assemble a classpath, possibly involving a download from remote artifact repository (read further, should become clearer).

In Gradle you need to specify different classpaths for different purposes - i.e. compiling vs running vs testing your application. Often these classpaths would have a lot in common, such as most of the time you would want the classes you used to build your code to be available when you run it - that’s why you can specify “inheritance” relationship between configurations.

Any 3rd party tool Gradle runs also needs a classpath (if it runs on a JVM, which is like 99% of the tools in the Java ecosystem).

Dependencies are abstract instructions, specifying the ordering of “things” in the configurations, as well as instructions how to retrieve them. The instructions can be as simple as pointing to existing jars and class directories, specifying abstract “GAV coordinates” (a Maven nomenclature, cataloguing libraries by group, I’d and version), or point to another project in the same build whose output you need to use.

When dependencies are “resolved”, they are turned into one or more artifacts. The artifacts are generally files and they are what ends up in the classpath.

The configurations, dependencies and artifacts have metadata, which is useful for specifying exactly what you want, as well as inspecting what you got. There is also the resolution process, which takes an unresolved configuration, where you specified what you want by adding dependencies, and enriches it with artifacts based on rules and repository definitions you configured (that’s why, it is of crucial importance when do you resolve your dependencies - the later-the better)

BTW, the term “configuration” comes from Apache Ivy and refers to “configuration management”, and not to “settings for my application”. It is not a great name, but has stuck for historical reasonable.

Let me know if this helps or you are still confused :slight_smile:

1 Like