简体   繁体   English

Gradle-Java项目的多重依赖

[英]Gradle - Mutiple Dependencies for Java Project

Just started tying to use gradle, but not getting far. 刚开始使用gradle绑定,但没有走远。 Please help. 请帮忙。

I've followed the documentation, but it only show single dependencies or dependencies that I can't get to work. 我遵循了文档,但是只显示了单个依赖项或无法使用的依赖项。 Here is my build.gradle file: 这是我的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.+'
}

The problem is when I type in gradle build on the command line I get: 问题是当我在命令行中输入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}

But looking at the documentation this should be fine. 但是查看文档应该没问题。 Also all the example build files I've found are rather small or only have a single dependency. 同样,我发现的所有示例构建文件都很小,或者只有一个依赖项。 Does anyone have any views about using gradle for large commercial projects. 有没有人对将gradle用于大型商业项目有任何看法。

Thanks Adam 谢谢亚当

You need to specify configuration (similar to Maven scope, ie compile , testCompile , etc) for each dependency: 您需要为每个依赖项指定配置(类似于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 is a part of alternative syntax to provide dependency coordinates ( group: 'junit', name: 'junit', version: '4.+' ), not a special keyword. group是提供依赖项坐标的替代语法的一部分( group: 'junit', name: 'junit', version: '4.+' ),而不是特殊关键字。

Also note that you need double quotes to use variables in strings: 另请注意,您需要双引号才能在字符串中使用变量:

compile "com.exlogs.officedb:common:${OFFICEDB_VERSION}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM