This message was deleted.
# community-support
s
This message was deleted.
f
Copy code
tasks.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 🙂
v
What do you mean with you "get into a fight with Gradle's up-to-date check"? As you do the actions as part of the task using
doLast
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.)
🤔 1
Btw. the
joinToString...
should probably just be an
asPath
👍 1
f
Okay... maybe I am not clear enough and miss understood something. The problem for me is, the compileJava task as defined above, do not result in the weaved/modified classes.
v
Can you maybe knit an MCVE?
f
Oh... my bad, I think it does work now. Not sure why I always saw the class not weaved 😓
👌 1
Thank you so much, the
asPath
work perfectly. Do you have some donation account on github or something? I would like to buy you a beer or coffee 😄
v
Do you have PayPal?
f
I think so 🙂 Haven't logged in for a long time but I can give it a try
v
If possible, please in EUR, I use the USD wallet mainly for something different 🙂 https://paypal.me/BjoernKautler
f
Give me sec 🙂
👍 1
Which country do you live, if I may ask? 🙂
v
Germany
f
Ah... close, thought if you would be in Sweden then there is some local mobile pay app everyone uses here 😛
v
Just my firstname is Swedish
😆 1
f
Okay, tried to send you a small "beer" package, let me know in case you do not receive anything 🙂
Otherwise wish you a good weekend 😄
v
Yep, already arrived, thanks so much 🙂
For you too
🙌 1
f
Hmmm... well not that easy with this thing.... I might need a bit more help 😛 when I tried the script in my large project, as it has configuration cache turned on, I got this error: `Task
: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 🙂
v
Noone said this will even near to be CC compatible 😄
You have build script reference by referencing
sourceSets
and I think also by using
copy
,
javaexec
, and
delete
directly
And
configurations
So yeah, for CC compatibility, you need to change a few things
f
aha... do you have some hints on how to change those? 🤔
Copy code
diff --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/")
                }
        }
👀 1
f
Wooo, this is pretty cool. Definity maps onto the points mentioned in the doc. Thank you so much, as you just saved my Friday evening 😄
👌 1