DEV Community

Cover image for Gradle - maven scopes cheat sheet
Artem Ptushkin
Artem Ptushkin

Posted on • Edited on

Gradle - maven scopes cheat sheet

This cheat sheet could help you to figure out what happens inside your project dependencies.

Basically, the knowledge of what kind of classes you have in runtime/compile classpath brings you opportunity to analyze any problems related to:

  • Runtime issues, such as: NoClassDefFounderror, NoSuchMethodError
  • Compilation issues, such when it should compile but it is not
  • Classpath resources

When you publish jar libraries on purpose to share the code and fetch it from the library consumer side, i.e. executable application you have to remember about transitive dependencies:

Transitive dependencies are fetched based on Maven scope rules inside the pom.xml file of published artifact

For example: when you fetch junit:4.12 from the maven central it brings the transitive dependencies from its pom.xml to your classpath.

Using gradle dependecy configurations to publish a jar you still write maven scopes into released pom.xml under the hood. It brings a need to better understand relations between these tools.

Gradle dependency configuration affects the dependencies of the publishing jar that's why it is important to pay attention to the build file configuration.

  • Artifact inclusion: if yes then this dependency will be included inside your fat jar (spring boot application etc.)/war file
  • Library consumer: how this dependency will affect consumer application when he declares it
  • Current artifact: how this dependency will affect this application classpath during compilation and runtime
  • You can find specific dependency at Intellij IDEA Gradle tab Alt Text

I published example gradle configuration at the github. You can call ./gradlew install and check build/poms/pom-default.xml generated file or take a look at one I saved.

Hope this article and sheet helps you with your jar investigations.

Top comments (0)