Gradle control transitive from dependency build.gradle

I’m not sure if this is feasible, but wanted to get some comments/solution for the problem.

I’m creating a new dependency com.example:app-dep:1.0.1 will be used in com.example:app as compile dependency.

app-dep having a dependency io.undertow:undertow-core:2.0.1.Final which I don’t want in com.example:app project, because I’m excluding the class file from com.example:app-dep related to undertow because the class requires on development time but not required in production.

When I add com.example:app-dep:1.0.1 in com.example:app I want to exclude io.undertow:undertow-core:2.0.1.Final .

But I want to control that from com.example:app-dep:1.0.1 maybe enable in future.

Some gradle I tried

app-dep - build.gradle

dependencies {
  implementation('io.undertow:undertow-core:2.0.1.Final') {
    transitive = true
  }
  implementation('io.undertow:undertow-servlet:2.0.1.Final') {
    transitive = false
  }
}

production-app build.gradle using spring-boot-gradle-plugin bootRepackage

buildscript {
  dependencies {
    classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.12.RELEASE"
  }
}
dependencies {
  compile 'com.example:app-dep:1.0.1'
}

OUTPUT: Still pulling and adding io.undertow:undertow-core:2.0.1.Final in production spring-boot jar

What I can do but I don’t want

In production-app build.gradle

dependencies {
  compile('com.example:app-dep:1.0.1') {
    exclude(module: 'com.example.app-dep')
  }
}

Because I want to control that from app-dep