Add files to jar in gradle kotlin

Viewed 131

My usecase is to copy files from another dependency and add it to the jar. For a build.gradle file it is done as

task copyConfiguration(type: Copy) {
 from("${brazilGradle.path('[ABC]pkg.src')}")
 into "${brazilGradle.buildDir}/schema"
}

sourceSets.main.resources {
 srcDir "${brazilGradle.buildDir}/schema"
 include 'src/*' 
}

What will be the equivalent translation for build.gradle.kts?

Edit : I was able to copy the file using

task<Copy>("copyDdlSchemas") {
    from("${brazilGradle.path("[ABC]pkg.src")}")
    into("${brazilGradle.buildDir}/schema")
}

Need help with syntax to upload it to jar.

1 Answers

If what you want is the kotlin gradle equivalent of the sourceSets section in the question, it'll look like below:

sourceSets["main"].resources {
    srcDir("${brazilGradle.buildDir}/schema")
    include("src/*")
}

Once the files are part of the source set, they'll automatically get included in the jar file generated by the default jar task.

Related