我试图编译和打包我的 java 应用程序,但在尝试指定我的本地存储库时遇到问题,我的 jars 将用作依赖项。我已将应用程序所需的所有 jar 存储在“/home/test/lib”中。我的 build.gradle 文件如下:
apply plugin:'application'
apply plugin:'java'
apply plugin:'idea'
def repositoryPath = '/home/test/lib'
repositories {
repositoryPath
}
dependencies {
"org.springframework:spring-orm:3.0.2.RELEASE"
"org.springframework:spring-context-support:3.0.2.RELEASE"
'commons-dbcp:commons-dbcp:1.4'
'org.apache.ibatis:ibatis-sqlmap:2.3.4.726'
'commons-dbutils:commons-dbutils:1.3'
'joda-time:joda-time:1.6'
'commons-lang:commons-lang:2.5'
'com.google.collections:google-collections:1.0'
}
jar {
baseName = 'testJar'
}
mainClassName = "com.some.test.testRunner"
当我运行 gradle build 时,出现“package * does not exist”错误。
我的假设是 gradle 没有在我的 lib 文件夹中找到必要的外部 jar。有人可以指出我在这里可能做错了什么。
谢谢
最佳答案
关于您的构建文件的一些评论。我假设您在“/home/test/lib”中有一个包含第三方库的平面目录?如果是这种情况,您可以使用 flatDir 存储库,它使用以下语法声明:
def repositoryPath = '/home/test/lib'
repositories {
flatDir {
dirs repositoryPath
}
}
如果/home/test/lib 是一个 ivy 仓库,你可以这样做:
repositories {
ivy {
url repositoryPath
}
}
这在 Gradle user guide 中有详细解释。 .
在您的“依赖项”部分中,您没有声明依赖项的范围(编译、运行时等):
dependencies {
compile "org.springframework:spring-orm:3.0.2.RELEASE"
compile "org.springframework:spring-context-support:3.0.2.RELEASE"
compile 'commons-dbcp:commons-dbcp:1.4'
compile 'org.apache.ibatis:ibatis-sqlmap:2.3.4.726'
compile 'commons-dbutils:commons-dbutils:1.3'
compile 'joda-time:joda-time:1.6'
compile 'commons-lang:commons-lang:2.5'
compile 'com.google.collections:google-collections:1.0'
}
如果您使用 flatdir 存储库,您的依赖项定义的组通常会被省略:
dependencies {
compile ":spring-orm:3.0.2.RELEASE"
...
}
查看 gradle 用户指南,了解有关使用 gradle 处理依赖项的详细信息:http://gradle.org/docs/current/userguide/userguide_single.html#artifact_dependencies_tutorial
问候, 雷内
关于java - 对本地存储库(gradle)中的依赖关系感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9590289/