MKB
MKB

Reputation: 7619

Remove transitive classpath dependency - plugins block

I want to remove the log4j transitive dependency from the shadow gradle plugin.

plugins {
  id 'com.github.johnrengelman.shadow' version '7.1.2'
}

I search for a solution but did not get any. I know I can remove this using the following code -

buildscript {
  repositories {
    gradlePluginPortal()
  }
  dependencies {
    classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.1.2', {
      exclude module: 'log4j'
    }
  }
}

But is there any way to do this with plugins block?

Upvotes: 1

Views: 1483

Answers (2)

MKB
MKB

Reputation: 7619

I used following code to exclude the dependency -

buildscript {
  repositories {
    ..
  }
  dependencies {
    ..
  }
  configurations.classpath {
    exclude module: 'log4j'
  }
}

plugins {
  id 'com.github.johnrengelman.shadow' version '7.1.2'
}

Upvotes: 1

Cisco
Cisco

Reputation: 23060

No, the plugins { } is itself a DSL which is limited by design. This is documented in the documentation:

https://docs.gradle.org/current/userguide/plugins.html#sec:constrained_syntax

The plugins {} block does not support arbitrary code. It is constrained, in order to be idempotent (produce the same result every time) and side effect free (safe for Gradle to execute at any time).

It is designed to do one thing and one thing only: apply plugins.

Upvotes: 1

Related Questions