Tasks created in the build.gradle file should have the ability to call other tasks

Listen to the jar file and recompile it
 What if I want to add an auto-compile task to a gradle task to detect if the dependent file has changed to rebuild it, but I can't call the build task.

This is pseudocode

task("autoBuild") {
    doLast {
        println("autoBuild")
        var str = ""
        while (true) {
            val md5AsBase64 = Md5Utils.md5AsBase64(file("xxx.jar"))
            if (!StringUtils.equals(str, md5AsBase64)) {
//gradle doesn't have this api, it just wants something similar
                tasks.build.get().execute()
                str = md5AsBase64
            }
            Thread.sleep(5000)
        }
    }
}

You cannot “call” other tasks.
That would have various problems and is simply not even faintly fitting in the architecture.

Luckily you don’t need such a task but can simply do ./gradlew build --continuous and as soon as Gradle sees relevant input files changed it will automatically rerun the build.

Thank you so much for your help! I would prefer to implement a simple jenkins with a task

What do you mean with “a simple jenkins”?
If you meant “I want to do it like my initial idea”, as I said, you simply cannot and probably never will.

jenkins Is an open source automation server ,I want to implement very simple jenkins with tasks, such as listening to http file server dependencies, recompiling changes, and then pushing them to another file server

I know what Jenkins is.
It just does not really make any sense to “implement Jenkins as Gradle tasks”.
It makes sense to implement all build / deployment / releasing / whatever logic as Gradle tasks, to be as independent from the CI tool as possible imho, so that you can easily switch them or also do the things locally if the CI server dies.

I personally greatly prefer TeamCity as CI server. Changing from Jenkins to TeamCity is like changing from Eclipse to IntelliJ IDEA or like changing from Maven to Gradle. :smiley:

But anyway, as I said, you cannot “call” a task.
If you want “rerun the build if input files were changed”, use the --continuous switch.