2012-11-30 42 views
0

刚刚开始绑定使用gradle,但没有走得太远。请帮忙。Java项目的Gradle - 多个依赖关系

我已经按照文档,但它只显示单一的依赖关系或依赖关系,我不能去工作。这里是我的build.gradle文件:

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} 

但看文档,这应该是罚款:

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在命令行中我得到的类型。我发现的所有示例构建文件都很小,或者只有一个依赖关系。有没有人对大型商业项目使用gradle有任何看法。

由于 亚当

回答

4

需要为每个依赖性指定配置(类似于Maven的范围,即compiletestCompile等):

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}" 
+0

感谢您的帮助,但花了几个小时试图让它工作,我仍然得到'无法解析所有的依赖后,配置':compile'.'尽管我直接从一个可以工作的build.xml文件中解除依赖关系。鉴于缺乏明确的文件,我认为gradle没有准备好主流。回到Maven - 并不是很好,但它确实可以开箱即用,而且文档是全面的,并且得到了很好的解释。 –

+0

嘿亚当,Gradle用于大型关键任务环境,用户指南包含超过300页,因此我无法理解您的论点。你能用“-i”选项发布运行你的版本的堆栈跟踪吗?也许我们可以找出你的构建失败的原因 –

+0

谢谢Rene,我会发布它,但我必须等到格林威治标准时间星期一现在。 –