Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要使用gradle构建文件从eclipse中排除依赖项_Eclipse_Gradle - Fatal编程技术网

需要使用gradle构建文件从eclipse中排除依赖项

需要使用gradle构建文件从eclipse中排除依赖项,eclipse,gradle,Eclipse,Gradle,我试图从gradle构建中排除依赖项,主要是“slf4j simple”。它工作得很好,但在运行“GradleEclipse”时没有得到反映 我的gradle构建文件中有以下代码: apply plugin:'war' apply plugin:'eclipse' apply plugin:'jetty' ... dependencies { compile 'mysql:mysql-connector-java:5.1.16' compile 'net.sourceforge.

我试图从gradle构建中排除依赖项,主要是“slf4j simple”。它工作得很好,但在运行“GradleEclipse”时没有得到反映

我的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文件中排除,这很好

当我运行'gradleeclipse'时,slf4j simple不会从eclipse类路径中排除

gradle食谱中提到了该问题的解决方案,但我不知道如何应用它:


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

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

对于gradle 1.0-milestone-3,我不得不对rodion的答案进行修改,以使其生效:

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

使用
EclipsPasspath
对我不起作用,但这确实起到了作用:

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

这将
commons日志记录
排除在可传递的范围之外(从项目对Spring的依赖中),也将
jcl-over-slf4j
排除在Eclipse项目的构建路径之外(我对
jcl-over-slf4j
有一个Gradle
runtime
依赖,但不希望它包含在构建(编译)中)路径。

这在Gradle 4.10中起作用

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

我有一个更重要的问题。我如何学习gradle并了解如何操作这些高级配置?我真的无法掌握它,每次我需要一些东西来发布问题。gradle在他们的官方网站上有相当好的文档。我从那里学到了我需要知道的一切(偶尔也可以查看Gradle源代码)。如果还有其他问题,请在这里或谷歌)使用EclipseKepler中的GradleIDE插件,这是行不通的。我有一个运行时依赖项,我正试图使用上面的方法排除它;Eclipse Gradle毫无怨言地运行build.Gradle,但项目构建路径仍然包含排除的工件。