Gradle 1.1 vs 2.0:无法确定任务的依赖关系:compileAcctJava'

时间:2014-07-21 15:09:16

标签: java gradle

Gradle 1.11给我一个弃用警告:

robert@pferdeapfel:~/prj> gradle --version | grep Gradle
Gradle 1.11

robert@pferdeapfel:~/prj> gradle compileJava
Converting class org.gradle.api.internal.file.DefaultSourceDirectorySet to File using
toString() method has been deprecated and is scheduled to be removed in Gradle 2.0.
Please use java.io.File, java.lang.String, java.net.URL, or java.net.URI instead.
:compileAcctJava
:processAcctResources UP-TO-DATE
:acctClasses
:resources
:acct UP-TO-DATE
:beans UP-TO-DATE
:svninfo UP-TO-DATE
:settings UP-TO-DATE
:compileJava UP-TO-DATE

BUILD SUCCESSFUL
Total time: 10.865 secs

并且Gradle 2.0无法构建:

robert@pferdeapfel:~/prj> /usr/local/gradle-2.0/bin/gradle --version | grep Gradle
Gradle 2.0

robert@pferdeapfel:~/prj> /usr/local/gradle-2.0/bin/gradle -i compileJava

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':compileAcctJava'.
> Cannot convert the provided notation to a File or URI: acct Java source.
  The following types/formats are supported:
    - A String or CharSequence path, e.g 'src/main/java' or '/usr/include'
    - A String or CharSequence URI, e.g 'file:/usr/include'
    - A File instance.
    - A URI or URL instance.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option
to get more log output.

BUILD FAILED

Total time: 3.676 secs

但是,我不知道为什么以及在我的构建脚本中的问题所在。

我已经定义了http://www.gradle.org/docs/current/userguide/java_plugin.html#sec%3asource_sets中描述的源集,因为我的项目不遵循默认的项目布局。

sourceSets {
    ...
    acct {
        java {
            srcDir "src"
            srcDirs("src") {
                include "my/program/some/package/Acct.java"
            }
        }
    }
    ...
}

我确实定义了一些依赖项,但不是acct;这只是一个简单的枚举,用作代码生成的基础。它没有依赖关系。即使我添加如下的虚拟依赖项,我也会遇到同样的错误。

dependencies {
    ...
    acctCompile junit
    ...
}

我该如何解决这个问题,或者如何才能找到更多关于究竟出错的地方?

我发现Gradle的--debug--stacktrace的输出完全没有帮助。

1 个答案:

答案 0 :(得分:2)

没有srcDirs("src") { include "my/program/some/package/Acct.java" }这样的表示法。尝试:

sourceSets {
    acct {
        java {
            srcDirs = ["src"] // replaces default rather than adding another dir
            include "my/program/some/package/Acct.java"
        }
    }
}