私はuser guideで作業しようとしています。これは私がやりたい信じられないほど単純なもののようですが、私はそれを動作させる方法を理解できません。gradle:グルーヴィーな仕事を書くには
タスクを定義するための外部groovyファイルを作成し、そのタスクをbuild.gradle
で呼び出したいとします。私は絶対に持って、この時点で
$ gradle tasks
FAILURE: Build failed with an exception.
* Where:
Build file '/projects/gradle/build.gradle' line: 21
* What went wrong:
A problem occurred evaluating root project 'gradle'.
> Could not get unknown property 'my' for root project 'gradle' of type org.gradle.api.Project.
* 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.193 secs
:
package my.package
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
class MyTask extends DefaultTask {
String greeting = 'hello from MyTask'
@TaskAction
def greet(){
println greeting
}
}
私もタスクをリストすることはできません:私はMyTask.groovy
を持ってsrc/main/groovy/my/package
の下で、その後
// Apply the groovy plugin to add support for Groovy
apply plugin: 'groovy'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// We use the latest groovy 2.x version for building this library
compile 'org.codehaus.groovy:groovy-all:2.4.7'
compile gradleApi()
compile localGroovy()
// We use the awesome Spock testing and specification framework
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'junit:junit:4.12'
}
task myTask (type: my.package.MyTask)
:ここに私のbuild.gradle
ファイルです何が起こっているのか、私がしたいことをどうやってやるのか分かりません。これは最も単純な可能性のある例のようですが、ユーザーガイドに従うと私はどこにもいません。私が何をしても、私はその例外を乗り越えることはできません。
groovyファイルを作成し、それを使ってビルドファイルに新しいタスクを定義するにはどうすればよいですか?
私は今、新しいエラーになったので、ありがとう。 Sidenote:それを変える方法はありますか?私はこれを学びたいので、大きなプロジェクトに貢献することができますが、大きなプロジェクトにはbuildSrcフォルダがありません – ewok
@ewokアップデートを確認してください – CMPS