【问题标题】:Need to exclude a dependency from eclipse using a gradle build file需要使用 gradle 构建文件从 eclipse 中排除依赖项
【发布时间】:2011-11-26 03:24:45
【问题描述】:

我正在尝试从我的 gradle 构建中排除一个依赖项,主要是“slf4j-simple”。它运行良好,但在我运行“gradle eclipse”时没有反映出来。

我的 gradle 构建文件中有以下代码:

apply plugin:'war'
apply plugin:'eclipse'
apply plugin:'jetty'
...
dependencies {
    compile 'mysql:mysql-connector-java:5.1.16'
    compile 'net.sourceforge.stripes:stripes:1.5'
    compile 'javax.servlet:jstl:1.2'
    ... (Rest of the dependencies)
}
configurations {
        all*.exclude group:'org.slf4j',module:'slf4j-simple'
}

现在,当我运行“gradle build”时,slf4j-simple 会从创建的 war 文件中排除,这很好。

当我运行“gradle eclipse”时,slf4j-simple 不会从 eclipse 类路径中排除。

gradle cookbook 中提到了该问题的解决方案,但我不明白如何应用它:

http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-ExcludingdependenciesfromEclipseProjects

【问题讨论】:

    标签: eclipse gradle


    【解决方案1】:

    这适用于 Gradle 4.10

    eclipse {
      classpath {            
        file {
          whenMerged { cp ->                  
            cp.entries.removeAll { (it instanceof Library)  && it.moduleVersion?.group == 'org.slf4j' && it.moduleVersion?.name == 'slf4j-simple' }
          }
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      使用eclipseClasspath 对我不起作用,但这可以解决问题:

      configurations {
          compile {
              exclude group: 'commons-logging'
              exclude module: 'jcl-over-slf4j'
          }
      }
      

      这不包括 commons-logging 被传递地包含(来自项目对 Spring 的依赖)以及 jcl-over-slf4j 不被包含在 Eclipse 项目的构建路径中(我有一个 Gradle runtime 依赖于 jcl-over-slf4j 但不要不希望它包含在构建(编译)路径中。

      【讨论】:

        【解决方案3】:

        对于 gradle 1.0-milestone-3,我必须对 rodion 的回答进行修改才能使其正常工作:

        eclipseClasspath{
        doFirst{
            plusConfigurations.each{
                it.allDependencies.each{ it.exclude group: 'org.slf4j', module: 'slf4j-simple' }
            }
           }
        } 
        

        【讨论】:

          【解决方案4】:

          尝试将其添加到您的 build.gradle:

          eclipseClasspath{
            plusConfigurations.each{
              it.allDependencies.each{ it.exclude group: 'org.slf4j', module: 'slf4j-simple' }
            }
          }
          

          【讨论】:

          • 我有一个更重要的问题。我如何学习 gradle 并了解如何操作这些高级配置?我真的抓不住它,每次我需要一些东西我都需要发布一个问题。
          • Gradle 在他们的官方网站上有很好的文档。我从那里学到了我需要知道的一切(偶尔也会查看 Gradle 源代码)。如有其他问题,请在此处或谷歌查询))
          • 在 Eclipse Kepler 中使用 Gradle IDE 插件不起作用。我有一个运行时依赖项,我试图使用上面的方法排除它; Eclipse Gradle 运行 build.gradle 没有任何问题,但项目构建路径仍然包含排除的工件。
          猜你喜欢
          • 2014-07-03
          • 2020-08-27
          • 2021-08-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-09-08
          相关资源
          最近更新 更多