You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a multiplatform project that contains a JVM target with additional Java sources (via withJava()). When applying the atomicfu plugin, the Java sources are no longer present in the jar. This can be mitigated by disabling this transformation (i.e. disabling the JVM transformation or using IR transforms).
For reproducing, the mpp-sample can be adjusted accordingly:
The bug is most likely caused by the rewiring of the compilations classes here:
At the very end, setFrom(...) is called to overwrite the classes, but this never considers the output of the Java compile task for KotlinJvmCompilations. A naive fix looks as follows. However, I'm unsure if this is a proper fix for this, as I'm unfamiliar with how exactly the transform functions. Maybe the Java sources should also be considered by the transformation?
diff --git a/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt b/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt
index 052550f..de08900 100644
--- a/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt+++ b/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt@@ -17,6 +17,7 @@ import org.gradle.util.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.plugin.*
+import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import org.jetbrains.kotlin.gradle.tasks.*
import java.io.*
import java.util.*
@@ -362,6 +363,9 @@ private fun Project.configureTransformationForTarget(target: KotlinTarget) {
//now transformTask is responsible for compiling this source set into the classes directory
compilation.defaultSourceSet.kotlin.destinationDirectory.value(transformedClassesDir)
classesDirs.setFrom(transformedClassesDir)
+ if (compilation is KotlinJvmCompilation) {+ classesDirs.from(compilation.compileJavaTaskProvider)+ }
classesDirs.setBuiltBy(listOf(transformTask))
tasks.withType(Jar::class.java).configureEach {
if (name == target.artifactsTaskName) {
The text was updated successfully, but these errors were encountered:
TheMrMilchmann
changed the title
The Gradle plugin discards Java sources in post-compile transformations
The Gradle plugin ignores Java sources in post-compile transformations
Mar 1, 2025
I have a multiplatform project that contains a JVM target with additional Java sources (
via withJava()
). When applying the atomicfu plugin, the Java sources are no longer present in the jar. This can be mitigated by disabling this transformation (i.e. disabling the JVM transformation or using IR transforms).For reproducing, the
mpp-sample
can be adjusted accordingly:The bug is most likely caused by the rewiring of the compilations classes here:
kotlinx-atomicfu/atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt
Lines 322 to 364 in b5db8fc
At the very end,
setFrom(...)
is called to overwrite the classes, but this never considers the output of the Java compile task forKotlinJvmCompilation
s. A naive fix looks as follows. However, I'm unsure if this is a proper fix for this, as I'm unfamiliar with how exactly the transform functions. Maybe the Java sources should also be considered by the transformation?The text was updated successfully, but these errors were encountered: