Jonathing
08/19/2025, 12:11 PMObjectFactory#newInstance (or whatever the internal version of that is) with service injection support or does it try to build the class raw using the saved values. Asking because I am using a transient private field that stores an instance of Problems which is normally provided through service injection in constructor parameter or bean getter.Vampire
08/19/2025, 12:21 PMJonathing
08/19/2025, 12:22 PMJonathing
08/19/2025, 12:22 PMVampire
08/19/2025, 12:33 PM@Transient annotation?Jonathing
08/19/2025, 12:34 PMtransient keyword in JavaJonathing
08/19/2025, 12:34 PMJonathing
08/19/2025, 12:34 PMVampire
08/19/2025, 12:37 PMI'm still an old-head using Java, sorryNo need to apologize, Java is also my main language and for a public Gradle plugin I would never use anything else, but plain Java with target set to the lowest version that is supported by the lowest supported Gradle version, so Java 8 unless it is Gradle 9 only. 🙂 Much better for compatibility and less headaches. 🙂
Jonathing
08/19/2025, 12:37 PMJonathing
08/19/2025, 12:38 PMJonathing
08/19/2025, 12:38 PMVampire
08/19/2025, 12:38 PMJonathing
08/19/2025, 12:38 PMVampire
08/19/2025, 12:39 PMJonathing
08/19/2025, 12:40 PMWorkerExecutor?Vampire
08/19/2025, 12:41 PMJonathing
08/19/2025, 12:42 PMJonathing
08/19/2025, 12:43 PMJonathing
08/19/2025, 12:43 PMWorkerExecutor in configuration before and found that it doesn't really work/do anythingVampire
08/19/2025, 12:43 PMVampire
08/19/2025, 12:44 PMJonathing
08/19/2025, 12:44 PMVampire
08/19/2025, 12:45 PMJonathing
08/19/2025, 12:45 PMJonathing
08/19/2025, 12:45 PMJonathing
08/19/2025, 12:45 PMVampire
08/19/2025, 12:45 PMVampire
08/19/2025, 12:46 PMJonathing
08/19/2025, 12:47 PMObjectFactory#newInstance to create it again. The class itself uses service injectors to get Problems and ProviderFactory and I use that as my Problems "wrapper" so to speakVampire
08/19/2025, 12:52 PMinterface ProblemsHolder {
@get:Inject
val problems: Problems
}
abstract class Foo : DefaultTask() {
@get:Inject
abstract val objects: ObjectFactory
@Transient
private val problemsHolder = objects.newInstance<ProblemsHolder>()
@TaskAction
fun execute() {
val problemId: ProblemId = ProblemId.create("adhoc-plugin-deprecation", "Task is deprecated", ProblemGroup.create("foo", "Foo"))
problemsHolder.problems.reporter.report(problemId) {
contextualLabel("Foo context")
documentedAt("https://no.where")
severity(Severity.ERROR)
solution("Do something else")
}
}
}
val foo by tasks.registering(Foo::class)
I think that should work fine.
Can you maybe show an MCVE of what you have that does not work?Vampire
08/19/2025, 12:55 PM@Transient, the Gradle-internal one instead of the Kotlin/JVM one.
Using the Kotlin/JVM one (should resemble the transient in Java afair) the field is null even if it is set in the constructor.Vampire
08/19/2025, 12:56 PMJonathing
08/19/2025, 12:58 PMJonathing
08/19/2025, 12:58 PMVampire
08/19/2025, 1:00 PMreadObject to fill it or something like that.
See https://docs.gradle.org/current/userguide/configuration_cache.html#serialization and https://docs.gradle.org/current/userguide/configuration_cache_status.html#config_cache:not_yet_implemented:java_serializationJonathing
08/19/2025, 1:01 PMJonathing
08/19/2025, 1:02 PMMikhail Lopatkin
08/22/2025, 4:45 PMBecause I wrap it in an object that contains convenient helper methodsI'm a bit late to the party, but why don't just serialize the wrapper object? Does it have some problematic state aside the
Problems service itself? Or does it implements Problems itself (this is known to cause issues)?Jonathing
08/22/2025, 4:47 PMProblems itself, which in hindsight I don't need to do as I never even call the getReporter() on it.Jonathing
08/23/2025, 4:59 PMwhy don't just serialize the wrapper object?This was a wonderful suggestion and ended up working perfectly for me. Thank you!