Slackbot
01/19/2024, 3:41 PMFuyang Liu
01/19/2024, 3:45 PMtasks.withType<JavaCompile>().configureEach {
doLast {
val mainSS = sourceSets["main"]
val source = mainSS.output.classesDirs.singleFile
copy {
from("src/main/resources/META-INF/")
into("${source}/META-INF/")
}
javaexec {
description = "Performs EclipseLink static weaving of entity classes"
val target = source
mainClass = "org.eclipse.persistence.tools.weaving.jpa.StaticWeave"
args = listOf("-persistenceinfo", source.toString(), "-classpath", configurations["runtimeClasspath"].joinToString(separator = System.getProperty("path.separator")), source.toString(), target.toString())
classpath = configurations["runtimeClasspath"]
}
delete {
delete("${source}/META-INF/")
}
}
}
tasks.withType<Copy>().configureEach{
includeEmptyDirs = false
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
So this is my setup, basically trying to follow a guide like this one. But I use kts now.
The interesting part is if I remove the delete("${source}/META-INF/") line, and build, then I can see in the .class file it got weaved, but then I got a duplication policy unset error... But if I leave the delete statement, the class will not be weaved in the end (maybe the weaved class get recompiled again?), so the claim in the article in the end is not correct or not working with newer gradles perhaps? Thanks 🙂Vampire
01/19/2024, 3:51 PMdoLast there should not be a problem with up-to-date checks.
(Btw. this big-hammer duplicates strategy is most probably not a good idea. In practically all cases I have seen so far where Gradle complained about missing duplicates strategy, setting it is just a work-around and it should be fixed instead. This could also be related to your problem of having weaved or not depending on what got copied first maybe.)Vampire
01/19/2024, 3:51 PMjoinToString... should probably just be an asPathFuyang Liu
01/19/2024, 3:53 PMVampire
01/19/2024, 3:54 PMFuyang Liu
01/19/2024, 3:57 PMFuyang Liu
01/19/2024, 4:00 PMasPath work perfectly. Do you have some donation account on github or something? I would like to buy you a beer or coffee 😄Vampire
01/19/2024, 4:03 PMFuyang Liu
01/19/2024, 4:05 PMVampire
01/19/2024, 4:05 PMFuyang Liu
01/19/2024, 4:05 PMFuyang Liu
01/19/2024, 4:08 PMVampire
01/19/2024, 4:08 PMFuyang Liu
01/19/2024, 4:09 PMVampire
01/19/2024, 4:10 PMFuyang Liu
01/19/2024, 4:12 PMFuyang Liu
01/19/2024, 4:12 PMVampire
01/19/2024, 4:12 PMVampire
01/19/2024, 4:12 PMFuyang Liu
01/19/2024, 4:30 PM:compileJava of type `org.gradle.api.tasks.compile.JavaCompile`: cannot serialize Gradle script object references as these are not supported with the configuration cache.`
I packed the mini sample here if you need 🙂Vampire
01/19/2024, 4:31 PMVampire
01/19/2024, 4:32 PMsourceSets and I think also by using copy, javaexec, and delete directlyVampire
01/19/2024, 4:32 PMconfigurationsVampire
01/19/2024, 4:33 PMFuyang Liu
01/19/2024, 4:37 PMVampire
01/19/2024, 4:39 PMVampire
01/19/2024, 4:49 PMdiff --git a/demo/build.gradle.kts b/demo/build.gradle.kts
index 17e00d2..1526269 100644
--- a/demo/build.gradle.kts
+++ b/demo/build.gradle.kts
@@ -28,15 +28,23 @@ tasks.withType<Test> {
useJUnitPlatform()
}
+interface A {
+ @get:Inject
+ val fs: FileSystemOperations
+ @get:Inject
+ val exec: ExecOperations
+}
tasks.withType<JavaCompile>().configureEach {
+ val mainSS by sourceSets.main
+ val source = mainSS.output.classesDirs.singleFile
+ val runtimeClasspath: FileCollection = configurations.runtimeClasspath.get()
+ val (fs, exec) = objects.newInstance<A>().let { it.fs to it.exec }
doLast {
- val mainSS = sourceSets["main"]
- val source = mainSS.output.classesDirs.singleFile
- copy {
+ fs.copy {
from("src/main/resources/META-INF/")
into("${source}/META-INF/")
}
- javaexec {
+ exec.javaexec {
description = "Performs EclipseLink static weaving of entity classes"
val target = source
mainClass = "org.eclipse.persistence.tools.weaving.jpa.StaticWeave"
@@ -44,13 +52,13 @@ tasks.withType<JavaCompile>().configureEach {
"-persistenceinfo",
source.toString(),
"-classpath",
- configurations["runtimeClasspath"].asPath,
+ runtimeClasspath.asPath,
source.toString(),
target.toString()
)
- classpath = configurations["runtimeClasspath"]
+ classpath = runtimeClasspath
}
- delete {
+ fs.delete {
delete("${source}/META-INF/")
}
}Fuyang Liu
01/19/2024, 5:12 PM