Slackbot
01/15/2024, 7:25 PMFuyang Liu
01/15/2024, 7:34 PM// Register a custom task of type Copy
tasks.register<Copy>("copyDirtySrcToBuild") {
// Configure the task to copy files from src to build/copied directory
if(layout.projectDirectory.dir("src").asFile.exists()) {
from(layout.projectDirectory.dir("src"))
exclude("**/*.java")
// "build/classes/java/main"
into(layout.buildDirectory.dir("classes/java/main"))
}
mustRunAfter("compileJava")
}
// Make the build task depend on the custom copy task
tasks.named("build") {
dependsOn("copyDirtySrcToBuild")
}
tasks.named("jar") {
dependsOn("copyDirtySrcToBuild")
}
tasks.named("compileJava") {
dependsOn("copyDirtySrcToBuild")
}
It seems that I need to add a bunch of those dependsOn? Otherwise the task will fail.Vampire
01/15/2024, 10:05 PMVampire
01/15/2024, 10:05 PMVampire
01/15/2024, 10:05 PMVampire
01/15/2024, 10:05 PMVampire
01/15/2024, 10:06 PMVampire
01/15/2024, 10:07 PMdependsOn, disturbs build cache or causes corrupt cache entries, disables other optimizations, ...Fuyang Liu
01/16/2024, 3:33 PMFuyang Liu
01/16/2024, 3:35 PMFuyang Liu
01/16/2024, 3:39 PMVampire
01/16/2024, 3:39 PMSync task that collects everything into a new directory and use that to run OSGi against instead of the compileJava output folder.
Something like
val foo by tasks.registering(Sync::class) {
from(sourceSets.main.get().output)
into(layout.buildDirectory.dir("foo"))
}
given the sources and resources are properly configured for the main source set.Fuyang Liu
01/16/2024, 3:44 PMVampire
01/16/2024, 3:45 PMmain source set." is true, they will also be added to the jars alreadyFuyang Liu
01/16/2024, 3:48 PMFuyang Liu
01/16/2024, 3:52 PM/src # which has all the source code + some dirty files
/META-INFO
/whatever.xml
/x.icon
And then in the Eclipse generated jar it looks like such:
/com.a.b... // source structure containing .class and some dirty abc.xml
/META-INFO
/whatever.xml
/x.icon
And then in the Eclipse generated bin (similar to build/classes/main/java/) it has
/com.a.b... // source structure containing .class and some dirty abc.xmlFuyang Liu
01/16/2024, 3:53 PMbin but all the dirty stuff beside code inside src should also be in build/classes/main/javaFuyang Liu
01/16/2024, 3:56 PMresource to point it onto `src`folder and somehow exclude all *.java files? 🤔Fuyang Liu
01/16/2024, 3:57 PMsourceSets.main.get().output will not include the dirty file besides Java file?Vampire
01/16/2024, 3:58 PMsourceSets {
main {
resources {
srcDir("src")
}
}
}Fuyang Liu
01/16/2024, 3:58 PMFuyang Liu
01/16/2024, 4:04 PMVampire
01/16/2024, 4:04 PMVampire
01/16/2024, 4:05 PMFuyang Liu
01/16/2024, 4:05 PMFuyang Liu
01/16/2024, 4:12 PMtasks.named("compileJava") {
finalizedBy("mergeClasssAndSrcDirtyFiles")
}
I guess now it is not a problem anymore as we do not write into the compile target folder, right?Vampire
01/16/2024, 4:22 PMcompileJava was run successfully (successfully because you also have a dependency on the compileJava output)Fuyang Liu
01/16/2024, 4:37 PM