引用静态lib目录时的gradle构建过程中的问题 [英] Problems during build when referencing static lib directory gradle

查看:1297
本文介绍了引用静态lib目录时的gradle构建过程中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的需要引用一些jar文件,它们既不是提供一个公开,也没有内部存储库的build.gradle文件。

I use a build.gradle file which needs to reference some jar files which are neither available on a public nor an internal repository.

正因为如此,我把jar文件到lib目录,低于我的Eclipse项目:

Because of that I put the jar files into a lib directory which is below my Eclipse project:

dependencies {
    ...
    compile files('lib/*.jar')
}

这工作,只要罚款,我运行或在Eclipse中导出我的计划。但是,当我尝试构建的gradle gradle这个失败,此错误:

This works fine as long as I run or export my program from within Eclipse. But when I try gradle build gradle fails with this error:

文件无法正常化的路径
  'C:\\工作区\\ MyProject的\\项目\\ LIB \\ *罐子

Could not normalize path for file 'C:\Workspaces\MyProject\project\lib\*.jar'.

我改变了路径的lib \\ *。JAR ,增加了一个领先的 ./ ,删除 \\ *。JAR 但无济于事。

I changed the path to lib\*.jar, added a leading ./, removed the \*.jar but to no avail.

当我从依赖删除编译文件线,将它添加到存储库,而不是

When I remove the compile files line from the dependencies and add this to repositories instead

repositories {
    ...
    flatDir { dirs './lib' }
}

编译器抱怨错误:无法找到符号,而所有这些符号是从lib目录中引用的罐子。
当我运行 --debug的gradle 我可以从日志中看到,flatDir引用的目录正在搜查:

the compiler complains about error: cannot find symbol, and all these symbols are in the jars referenced from the lib directory. When I run gradle --debug I can see from the log that the directory referenced by flatDir is being searched in:

10:02:20.587 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ResourceVersionLister] using org.gradle.internal.resource.transport.file.FileResourceConnector@48499739 to list all in /C:/...../lib/ 
10:02:20.592 [DEBUG] [org.gradle.api.internal.artifacts.repositories.resolver.ResourceVersionLister] found 7 urls

7的文件在lib目录中的数量。

7 is the count of files in the lib directory.

为什么这项工作在Eclipse(STS 3.7的gradle用工具),而不是通过命令行?我试过的gradle都2.2.1和2.5。

Why does this work in Eclipse (STS 3.7 with gradle tooling) and not from the command line ? I tried both gradle 2.2.1 and 2.5.

推荐答案

您需要使用文件树而不是FileCollection的:

You need to use a FileTree instead of a FileCollection:

compile fileTree(dir:'lib', include:'*.jar')

为什么日食的表现比你不同的gradle的原因很可能是因为你没有运行日食的gradle (由Eclipse插件添加了一个任务)。
Eclipse不互动与你的build.gradle在所有自然。这次日食任务更新您的日食将在与gradle这个snyc。

The reason why eclipse behaved differently than your gradle is most likely because you didn't run gradle eclipse (a task added by the eclipse plugin). Eclipse does not interact with you build.gradle at all naturally. The eclipse task updates your eclipse to be in snyc with gradle.

这篇关于引用静态lib目录时的gradle构建过程中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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