簡體   English   中英

Gradle-Java項目的多重依賴

[英]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范圍,即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}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM