How to tell whether a dependency should have "compile" or "runtime" scope

(Chris Rankin) #1

I am trying to write <dependency/> elements for a Maven POM, but am struggling to set the <scope/> element correctly because I cannot determine whether something is a runtimeElement or an apiElement.

Consider this fragment of build.gradle:

configurations {
    configA.extendsFrom api
    configB.extendsFrom implementation

dependencies {
    configA "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    configB "org.slf4j:slf4j-simple:$slf4j_version"

configurations.configA.resolvedConfiguration.firstLevelModuleDependencies.forEach {
    println("${it.module} from ${it.configuration}")

configurations.configB.resolvedConfiguration.firstLevelModuleDependencies.forEach {
    println("${it.module} from ${it.configuration}")

This fragment generates the following output:

org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.61 from default
org.slf4j:slf4j-simple:1.7.25 from default

When I set enableFeaturePreview('IMPROVED_POM_SUPPORT') in settings.gradle, I get this instead:

org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.61 from runtime
org.slf4j:slf4j-simple:1.7.25 from runtime

What I would like to see is something more like this, of course:

org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.61 from compile
org.slf4j:slf4j-simple:1.7.25 from runtime

Is there any programmatic way that I can determine whether a given dependency should be either compile or runtime please?

Note: We can safely assume that I am asking this because

publishing {
  publications {
    myPublication(MavenPublication) {

does not generate the correct dependencies for my particular use case.