2013-05-28 86 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'存储库。 –

相关问题