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

发布于 2024-12-06 15:34:13 字数 875 浏览 0 评论 0原文

我试图从我的 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 食谱中提到了该问题的解决方案,但我不明白如何应用它:

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

I'm trying to exclude a dependency, mainly "slf4j-simple" from my gradle build. It works well, but is not reflected when I run "gradle eclipse".

I have the following code in my gradle build file:

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'
}

Now, when I run 'gradle build', the slf4j-simple is excluded from the war file created which is fine.

When I run 'gradle eclipse', the slf4j-simple is not excluded from the eclipse classpath.

A solution to the problem is mentioned in the gradle cookbook but I don't understand how to apply it:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

給妳壹絲溫柔 2024-12-13 15:34:13

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

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

Try adding this to your build.gradle:

eclipseClasspath{
  plusConfigurations.each{
    it.allDependencies.each{ it.exclude group: 'org.slf4j', module: 'slf4j-simple' }
  }
}
坚持沉默 2024-12-13 15:34:13

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

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

With gradle 1.0-milestone-3 I had to do a modification from rodion's answer to make it work:

eclipseClasspath{
doFirst{
    plusConfigurations.each{
        it.allDependencies.each{ it.exclude group: 'org.slf4j', module: 'slf4j-simple' }
    }
   }
} 
少女情怀诗 2024-12-13 15:34:13

使用 eclipseClasspath 对我来说不起作用,但这确实有窍门:

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

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

Using eclipseClasspath didn't work for me, but this does the trick:

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

That excludes commons-logging from being included transitively (from the project's dependency on Spring) and also jcl-over-slf4j from being included in the Eclipse project's build path (I have a Gradle runtime dependency on jcl-over-slf4j but don't want it included on the build (compile) path.

心欲静而疯不止 2024-12-13 15:34:13

这适用于 Gradle 4.10

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

This works in Gradle 4.10

eclipse {
  classpath {            
    file {
      whenMerged { cp ->                  
        cp.entries.removeAll { (it instanceof Library)  && it.moduleVersion?.group == 'org.slf4j' && it.moduleVersion?.name == 'slf4j-simple' }
      }
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文