This message was deleted.
# plugin-development
s
This message was deleted.
v
Even if you could that wouldn't help much. Assuming you speak about
classLoaderIsolation
. Even if you stay within one task instance and ensure the tasks are run sequentially it always uses a fresh class loader. I tried with
Copy code
workQueue.submit(FooAction::class) {}
workQueue.await()
workQueue.submit(FooAction::class) {}
workQueue.await()
Without the awaits, the tasks are run in parallel, so couldn't be reused anyway. With
processIsolation
it is different as spinning up worker processes is much more costly, so there they have deduplication. With above test code, even multiple instances of the task where each has a different
workQueue
reuse the worker process as it is free by the waiting. Without the waiting multiple are created to run in parallel, but those reused.
So if you would want a reuse with classloader isolation, you would first need to request this as feature and then it hopefully would work like with the process isolation without the need to manually share the work queue.
Here my full play code if you want to play with it yourself:
Copy code
val fooConfiguration by configurations.dependencyScope("foo")
dependencies {
    fooConfiguration("commons-io:commons-io:+")
}
val fooClasspathConfiguration = configurations.resolvable("fooClasspath") {
    extendsFrom(fooConfiguration)
}
abstract class FooAction : WorkAction<WorkParameters.None> {
    override fun execute() {
        val classLoader = Class.forName("org.apache.commons.io.Charsets").classLoader
        println("classLoader: ${System.identityHashCode(classLoader)} / $classLoader")
    }
}
abstract class FooTask : DefaultTask() {
    @get:Inject
    abstract val workerExecutor: WorkerExecutor

    @TaskAction
    fun foo() {
        println("workerExecutor: ${System.identityHashCode(workerExecutor)} / $workerExecutor")
        val workQueue = workerExecutor.classLoaderIsolation {
            classpath.from(project.configurations.named("fooClasspath"))
        }
        println("workQueue: ${System.identityHashCode(workQueue)} / $workQueue")
        workQueue.submit(FooAction::class) {}
        workQueue.await()
        workQueue.submit(FooAction::class) {}
        workQueue.await()
    }
}
val foo by tasks.registering(FooTask::class)
val bar by tasks.registering(FooTask::class)
Then kick off
gw foo bar
. Only things I changed are
await
or not
await
and
classLoaderIsolation
vs.
processIsolation
.
thank you 1
🤩 1
m
Wow, thank you very much for the in-depth answer 💙!
you would first to request this as feature and then it hopefully would work like with the process isolation without the need to manually share the work queue.
I see, yep having that dedup made automagically would be the best indeed 👍 . I'll try to benchmark the cost, make sure that's a real problem before opening an issue.
👌 1