2013-05-28 81 views
0

嗨,大家好,我是gradle新手,遇到以下問題。gradle在編譯時不使用編譯時依賴項

當我在項目中使用java插件並調用$ gradle build時,它不會將我的第三方依賴關係放在類路徑上。我的build.gradle文件看起來如下:

apply plugin: 'java' 

sourceSets.main.java.srcDirs = ["src/main/java", "src/main/web"] 

repositories { 
    flatDir name: 'thirdParty', dirs: 'C:/dev/repo' 
} 

dependencies { 
    compile files('log4j-1.2.12.jar', 'gson-1.7.1.jar') 
} 

和gradle這個輸出誤差以下

C:\dev\gradling\TestProject\src\main\web\java\org\gradle\example\simple\HelloWorld2.java:3: package com.google.gson does not exist 
import com.google.gson.Gson; 
        ^
C:\dev\gradling\TestProject\src\main\web\java\org\gradle\example\simple\HelloWorld2.java:7: cannot find symbol 
symbol : class Gson 
location: class org.gradle.example.simple.HelloWorld2 
     Gson gson = new Gson(); 
     ^
C:\dev\gradling\TestProject\src\main\web\java\org\gradle\example\simple\HelloWorld2.java:7: cannot find symbol 
symbol : class Gson 
location: class org.gradle.example.simple.HelloWorld2 
     Gson gson = new Gson(); 

我已表示我的回購罐子住的地方,並告訴它,當它編譯它必須包括上面提到的罐子。

請幫忙。

回答

0

您的依賴聲明不正確。您可以要麼指定flatDir回購和使用通常依賴語法外部依賴(group:module:version),用正確的文件路徑一起使用files方法(那麼你並不需要聲明一個庫)。在前一種情況下,您可以省略依賴組的組。例如:

repositories { 
    flatDir name: 'thirdParty', dirs: 'C:/dev/repo' 
} 

dependencies { 
    compile ':log4j:1.2.12' 
} 

欲瞭解更多信息,請參閱Gradle User Guide

+0

謝謝,冒號符號做到了。你有沒有辦法直接硬編碼你想在上面的例子中包含的jar文件? – n4rzul

+0

正如我所說的,你可以使用'files(「絕對/或/相對/路徑/到/ the.jar」)'。例如,如果Jars位於相對於版本根目錄的位置,則可以執行'files(「$ rootDir/some/path」)''。如果遵循這種方法,則不需要聲明'flatDir'存儲庫。 –

相關問題