gradle在构建时不使用编译时依赖项

时间:2013-05-28 22:03:42

标签: build 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();

我已经说过我的回购罐子在哪里生活并告诉它,当它编译时它必须包括上面提到的罐子。

请帮忙。

1 个答案:

答案 0 :(得分:0)

您的依赖声明不正确。你可以 指定一个flatDir repo,并使用通常的外部依赖关系语法(group:module:version),使用files方法与正确的文件路径(然后您不需要声明存储库)。在前一种情况下,您可以省略依赖关系组。例如:

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

dependencies {
    compile ':log4j:1.2.12'
}

有关详细信息,请参阅Gradle User Guide