Java Gradle多模块项目从子模块调用常见任务

Java Gradle多模块项目从子模块调用常见任务,java,gradle,build,build.gradle,Java,Gradle,Build,Build.gradle,我有一个Java项目的多模块设置,结构如下 mainApp |--> core-module | |--> src | |--> build.gradle | |--> gradle.properties | |--> lib-module | |--> src | |--> build.gradle | |--> gradle.properties |-->

我有一个Java项目的多模块设置,结构如下

mainApp
|--> core-module
|       |--> src
|       |--> build.gradle
|       |--> gradle.properties
|       
|--> lib-module
|       |--> src
|       |--> build.gradle
|       |--> gradle.properties
|--> lib-another-module
|       |--> src
|       |--> build.gradle
|       |--> gradle.properties
|--> settings.gradle
|--> build.gradle
mainApp/build.gradle中

task('collectBundles', type: Copy) {
    dependsOn "core-module:jar","lib-module:jar","lib-another-module:jar"
        
    into "$buildDir/image/"

    into("lib") {
        from project('core-module').file('build/libs/core-module.jar')
        from project('lib-module').file('build/libs/core-module.jar')
        from project('lib-another-module').file('build/libs/lib-another-module.jar')
    }
    outputs.upToDateWhen { false }
}
这个
dependsOn
我正在尝试解决,但是我遇到了错误

task('collectBundles', type: Copy) {
    dependsOn subprojects.finaAll { it.tasks.findByName("jar") }
        
    into "$buildDir/image/"

    into("lib") {
        from project('core-module').file('build/libs/core-module.jar')
        from project('lib-module').file('build/libs/core-module.jar')
        from project('lib-another-module').file('build/libs/lib-another-module.jar')
    }
    outputs.upToDateWhen { false }
}
甚至我也尝试了
dependsOn subprojects.findResult{it.tasks.findByName(“jar”)}

我也有错误

* What went wrong:
A problem occurred evaluating root project 'connectors'.

> Could not find method register() for arguments [{type=class org.gradle.api.tasks.Copy}, collectBundles, build_9f9pperbss2o8q2l4apsb5p9d$_run_closure15@c3c2ad7] on task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.
> ```

在哪里定义了
findResult
?在您的第一个示例中,我猜您正在使用,但是您可能应该使用,因为
findAll
作为一个过滤器,不会返回任务,而是返回子项目。哦,我认为它是
Gradle API