开发者

Need to exclude a dependency from eclipse using a gradle build file

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 'j开发者_开发百科avax.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


Try adding this to your build.gradle:

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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜