Search code examples
mavengradleparent-pom

Gradle dependency scopes


I was experimenting a little bit with Gradle but as mainly being a Maven user, some dependency scopes are confusing me …

Some are identical to Maven:

compile -> compile
runtime -> runtime
compileOnly -> provided

but I also encounter implementation which sounds like the parent element of Maven POM but then again also not.

Can somebody explain me what is implementation and some other if they exist and I didn’t mention here (test versions of above are clear no need to explain)?

And if implementation is not like parent on Maven, how can we have the parent POM effect of Maven in Gradle?


Solution

  • As commented, please have a look at the documentation or even at this recent webcast (disclaimer: I am co-presenting that webcast)

    As for the Maven comparison, view migrating / learning from Maven to Gradle the same as moving from subversion to git: while some vocabulary is the same, understanding the model of the later helps more than comparing.

    In short:

    • Do not use compile or runtime in Gradle, they are deprecated.
    • implementation relates to dependencies that are required to compile and run your application.
    • compileOnly and runtimeOnly should be self-explanatory in the context of the above
    • The java-library plugin adds the api configuration which is reserved for dependencies that consumers of your library will need to compile.

    There is no direct equivalent to a Maven parent pom. Whether you are talking about plugins, build config or dependencies, the way to centralize are different. Have a look at the documentation on multi-project authoring.