需要使用 gradle 构建文件从 eclipse 中排除依赖项
我试图从我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试将其添加到您的 build.gradle 中:
Try adding this to your build.gradle:
对于 gradle 1.0-milestone-3,我必须对 rodion 的答案进行修改才能使其工作:
With gradle 1.0-milestone-3 I had to do a modification from rodion's answer to make it work:
使用
eclipseClasspath
对我来说不起作用,但这确实有窍门:这排除了
commons-logging
被传递地包含在内(来自项目对 Spring 的依赖)以及>jcl-over-slf4j
被包含在 Eclipse 项目的构建路径中(我有一个 Gradleruntime
依赖于jcl-over-slf4j
但不想它包含在构建(编译)路径中。Using
eclipseClasspath
didn't work for me, but this does the trick:That excludes
commons-logging
from being included transitively (from the project's dependency on Spring) and alsojcl-over-slf4j
from being included in the Eclipse project's build path (I have a Gradleruntime
dependency onjcl-over-slf4j
but don't want it included on the build (compile) path.这适用于 Gradle 4.10
This works in Gradle 4.10