[英]Gradle - Mutiple Dependencies for Java Project
刚开始使用gradle绑定,但没有走远。 请帮忙。
我遵循了文档,但是只显示了单个依赖项或无法使用的依赖项。 这是我的build.gradle文件:
apply plugin: 'java'
sourceCompatibility = 1.7
OFFICEDB_VERSION = 'JAN12R2'
repositories {
mavenCentral()
}
dependencies {
compile group:
'org.hibernate:hibernate-validator:5.0.0.Alpha1',
'javax.validation:validation-api:1.1.0.Alpha1',
'com.exlogs.officedb:common:${OFFICEDB_VERSION}',
'com.exlogs.officedb:officedb-service:${OFFICEDB_VERSION}',
'com.exlogs:eventhub:1.0.0-RC1',
'commons-httpclient:commons-httpclient:3.1'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
问题是当我在命令行中输入gradle build
时,我得到了:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Dev\Code\officedb\manpower\build.gradle' line: 10
* What went wrong:
A problem occurred evaluating root project 'manpower'.
> Could not create a dependency using notation: {group=org.hibernate:hibernate-validator:5.0.0.Alpha1}
但是查看文档应该没问题。 同样,我发现的所有示例构建文件都很小,或者只有一个依赖项。 有没有人对将gradle用于大型商业项目有任何看法。
谢谢亚当
您需要为每个依赖项指定配置(类似于Maven范围,即compile
, testCompile
等):
dependencies {
compile 'org.hibernate:hibernate-validator:5.0.0.Alpha1'
compile 'javax.validation:validation-api:1.1.0.Alpha1'
compile "com.exlogs.officedb:common:${OFFICEDB_VERSION}"
compile "com.exlogs.officedb:officedb-service:${OFFICEDB_VERSION}"
compile 'com.exlogs:eventhub:1.0.0-RC1'
compile 'commons-httpclient:commons-httpclient:3.1'
testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile 'org.mockito:mockito-all:1.9.0'
}
group
是提供依赖项坐标的替代语法的一部分( group: 'junit', name: 'junit', version: '4.+'
),而不是特殊关键字。
另请注意,您需要双引号才能在字符串中使用变量:
compile "com.exlogs.officedb:common:${OFFICEDB_VERSION}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.