我的Gradle项目依赖于commons-io 2.4,但Gradle将$ GRADLE_HOME / commons-io-1.4.jar放入类路径中,导致失败 [英] My Gradle project depends on commons-io 2.4, but Gradle puts $GRADLE_HOME/commons-io-1.4.jar into the classpath, causing failures

查看:1130
本文介绍了我的Gradle项目依赖于commons-io 2.4,但Gradle将$ GRADLE_HOME / commons-io-1.4.jar放入类路径中,导致失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在迭代我的第一个Gradle插件中的功能。我早就确定我需要commons-io,所以我添加了对commons-io 2.4的依赖,这是最新版本。



这一直持续一段时间,在构建工作从命令行,没有错误在Eclipse中。

我刚开始尝试集成一些代码,使用FileUtils.write(文件,字符串) 。我以前不需要这种方法。我在Eclipse中获得了一切无法修改的内容,然后我尝试了一个命令行构建。



失败,出现如下错误:

  ...错误:无法找到符号
FileUtils.write(serviceLoaderFile,
^
symbol:方法write(File,String )
location:class FileUtils

这让我很困惑,我去了Eclipse中的失败行,并没有指出任何问题,我导航到了write()方法,对我来说看起来很好,然后我用--debug运行我的命令行版本以获得一些线索。



当我找到javac这一行时,我发现$ GRADLE_HOME \lib\commons-io-1.4.jar(其中GRADLE_HOME只是我的Gradle 2.3发行版)在我的依赖jar包的类路径中,然后检查了1.4 jar中的代码,并确定该版本中的FileUtils类没有写方法。



我是谁为此做了什么?



更新



我想这可能是我的依赖关系块将是有用的,这是:

 依赖关系{
compile(org.codehaus.groovy :groovy-all:2.3.9)
编译gradleApi()
编译org.opendaylight.yangtools:yang-parser-impl:0.7.0 -snapshot
compileorg。 opendaylight.yangtools:binding-java-api-generator:0.7.0-SNAPSHOT
compileorg.opendaylight.yangtools:binding-generator-api:0.7.0 -snapshot
compileorg。 opendaylight.yangtools:binding-generator-impl:0.7.0-SNAPSHOT
compileorg.opendaylight.controller:yang-jmx-generator:0.3.0 -snapshot
compilecommons-io: commons-io:2.4

testCompile(org.spockframework:spock-core:1.0-groovy-2.3){
exclude group:org.codehaus.groovy
}

我试着注释掉gradleApi引用,但这没有任何作用。我也尝试在groovy-all参考文献中添加与commons-io相关的排除,但这似乎也没有任何区别。
}

解决方案

解决方案需要将以下代码块添加到sourceSets块中:

  main {
compileClasspath = configurations.compile.minus文件($ gradle.gradleHomeDir / lib / commons-io-1.4.jar )
}

这很简单,但我希望有一个更清晰的解决方案这个。我不确定那会是什么样子。


I've been iterating on features in my first Gradle plugin. I determined early on that I needed commons-io, so I added a dependency on commons-io 2.4, being the latest version.

This has been going well for a while, with the build working from the command line, and no errors in Eclipse.

I just started trying to integrate some code that uses "FileUtils.write(File,String)". I didn't need that method before. I got everything un-redded in Eclipse, and then I tried a command line build.

This failed with errors like the following:

    ... error: cannot find symbol
                FileUtils.write(serviceLoaderFile,
                         ^
  symbol:   method write(File,String)
  location: class FileUtils

This confused me. I went to the failing lines in Eclipse, and no issues were indicated. I navigated into the "write()" method, and it looked fine to me. I then ran my command-line build with "--debug" to get some clues.

When I found the "javac" line, I found that "$GRADLE_HOME\lib\commons-io-1.4.jar" (where "GRADLE_HOME" is just my Gradle 2.3 distribution) was in the classpath BEFORE my dependency jar. I then inspected the code in the 1.4 jar, and I determined that the "FileUtils" class in that version didn't have a "write" method.

What am I supposed to do about this?

Update:

I suppose it's likely my "dependencies" block would be useful, which is this:

dependencies {
  compile ("org.codehaus.groovy:groovy-all:2.3.9")
  compile gradleApi()
  compile "org.opendaylight.yangtools:yang-parser-impl:0.7.0-SNAPSHOT"
  compile "org.opendaylight.yangtools:binding-java-api-generator:0.7.0-SNAPSHOT"
  compile "org.opendaylight.yangtools:binding-generator-api:0.7.0-SNAPSHOT"
  compile "org.opendaylight.yangtools:binding-generator-impl:0.7.0-SNAPSHOT"
  compile "org.opendaylight.controller:yang-jmx-generator:0.3.0-SNAPSHOT"
  compile "commons-io:commons-io:2.4"

  testCompile("org.spockframework:spock-core:1.0-groovy-2.3") {
    exclude group: "org.codehaus.groovy"
  }

I tried commenting out the "gradleApi" reference, and that had no effect. I also tried adding an "exclude" for commons-io associated with the "groovy-all" reference, but that also didn't appear to make any difference. }

解决方案

The solution to this required adding the following block to the "sourceSets" block:

main {
    compileClasspath = configurations.compile.minus files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")
}

This is pretty simple, but I wish there was a cleaner solution for this. I'm not sure what that would look like.

这篇关于我的Gradle项目依赖于commons-io 2.4,但Gradle将$ GRADLE_HOME / commons-io-1.4.jar放入类路径中,导致失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆