【问题标题】:Remove transitive classpath dependency - plugins block删除传递类路径依赖 - 插件块
【发布时间】:2022-01-05 13:42:42
【问题描述】:

我想从 shadow gradle 插件中移除 log4j 传递依赖。

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

我正在寻找解决方案,但没有得到任何解决方案。我知道我可以使用以下代码删除它 -

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

但是有没有办法通过插件块来做到这一点?

【问题讨论】:

    标签: gradle build build.gradle gradle-plugin


    【解决方案1】:

    不,plugins { } 本身就是受设计限制的 DSL。这记录在文档中:

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

    plugins {} 块不支持任意代码。它是受约束的,以便幂等(每次产生相同的结果)和无副作用(Gradle 可以随时安全地执行)。

    它旨在做一件事,而且只做一件事:应用插件。

    【讨论】:

    • 是的,只支持几个参数。 id、版本和应用。
    【解决方案2】:

    我使用下面的代码来排除依赖-

    buildscript {
      repositories {
        ..
      }
      dependencies {
        ..
      }
      configurations.classpath {
        exclude module: 'log4j'
      }
    }
    
    plugins {
      id 'com.github.johnrengelman.shadow' version '7.1.2'
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-04
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 2011-12-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      相关资源
      最近更新 更多