Gradle generate zip with jars excluding sub-projects

I have multi-module project. I am using the following Gradle script to build zip which contains the sub-project’s jar along with its dependencies.

dependencies {
    api(project(":sub-project1"))
    implementation(project(":sub-project2"))

    implementation("some:lib:1")
    implementation("some:lib:2")

}

tasks.register<Zip>("buildZip") {
    archiveFileName.set("filename.zip")
    from(tasks.jar)
    from(configurations.runtimeClasspath)
}

The generated zip file will have all the jars of project1 and project2 along with dependency jars mentioned in the current sub-project.

My requirement is, I want to exclude jar files from project1 and project2 (along with dependency jars from there) and only include this sub-project’s jar and dependencies mentioned in this sub-project.

How can this be achieved ? Any help is appreciated. Thanks.