Need a bit of help whit converting a bit of a strange maven build

I need to do some tings i would never usually do in a build. But it’s big and i just need to get it compiling be fore i can clean it up.
I’m using the kotlin dsl so pleace us it in examples as im new to that dsl and had a 2 year break from gradle

  1. I need to depend on the test code.
    The maven code has some dependencies on another modules test code.
    So i need testImplementation(project(":common")) to say that it’s the test code it dependent on.

  2. They do download some dependencies and copy the files from the for future processing.
    I think this is what i need build.gradle - Gradle, extracting a dependency zip and using the content in its file? - Stack Overflow But a example in how to do it whit the kotlin dsl would help me learn.

  3. In one case it downloads a artifact, unzips files and generates code from it.
    I have this code, but wondering how i can enable cashing so the task will know if the files have changed. Now it runs every time

This code is what i have so far where code generation works but not cashing. the stuff im missing are from points 1 and 2. And don’t worry when i have it running like the maven build ill start cleaning

plugins {
    `java`
}

val tool by configurations.creating
val downloadMe by configurations.creating


tasks {
    //add a task to unzip the files from the dependensy

    register<JavaExec>("genCode") {
        description = "Generate code"
        classpath = tool
        main = "com.foo.bar.Generator"
        args(
                "com.bar.foo",//target namespace
                "$projectDir/templates/",//inn folder
                "$buildDir/generated-sources/com/bar/foo/",
                "some more args",
                "even more args"
        )
    }

    named<JavaCompile>("compileJava") {
        dependsOn(":subproject:genCode")//i had to add the project her. If i could just refere to the task over it would be nice
    }
}

sourceSets {
    main {
        java {
            srcDir("$buildDir/generated-sources")
        }
    }
}

dependencies {
    implementation(project(":someproject))// need to depend on the tests
    //other normal dependensies for complile and test
    tool(project(":generator"))
    downloadMe("some maven artifact")
}