What is the alternative to ```val compilations: Na...
# gradle
j
What is the alternative to
Copy code
val compilations: NamedDomainObjectContainer<out KotlinCompilation<KotlinCommonOptionsDeprecated>>
I am getting the main compilation but
KotlinCommonOptions
are deprecated
Copy code
val KotlinTarget.mainCompilation: KotlinCompilation<KotlinCommonOptions>?
    get() = compilations.findByName("commonMain") ?: compilations.findByName("main")
h
What exactly do you want to do? Setting up compiler options? There is a new toplevel compilerOptions property.
j
Is that extension on
KotlinProjectExtension
? I cannot find it
👌 1
Copy code
configure<KotlinProjectExtension> {
    targets.map { target ->
        val testFixturesCompilation = target.testFixturesCompilation
        val mainCompilation = target.mainCompilation
        if (testFixturesCompilation != null && mainCompilation != null) {
            testFixturesCompilation.associateWith(mainCompilation)
        }
    }
}
image.png
Maybe it is on each specific extension...
Anyway I am not sure how to get the compilations from
compilerOptions
anyway, there is no
compilations
property
e
Maybe it is on each specific extension...
yes, there are extension types and compiler options types for different plugin types
depending on whether it's a single-target plugin or the multiplatform plugin, there's
Copy code
kotlin {
    target {
        compilations
Copy code
kotlin
    targets.all {
        compilations
j
But getting a compilation from that
compilations
is reported as deprecated
e
for JVM test fixtures, the only work with the JVM plugin anyway so
Copy code
kotlin.target.compilations {
    named { it == "testFixtures" }.all { associateWith(getByName("main")) }
}
it's not deprecated on specific types as far as I can see
j
I am not sure, I am doing this:
Copy code
private val KotlinProjectExtension.targets: Iterable<KotlinTarget>
    get() =
        when (this) {
            is KotlinSingleTargetExtension<*> -> listOf(this.target)
            is KotlinMultiplatformExtension -> targets
            else -> error("Unexpected 'kotlin' extension $this")
        }
Copy code
private val KotlinTarget.mainCompilation: KotlinCompilation<KotlinCommonOptions>?
    get() = compilation(COMMON_MAIN) ?: compilation(MAIN)
Copy code
lazyConfigurable(isEnabled = isTestFixturesFullEnabled) {
    configure<KotlinProjectExtension> {
        targets.map { target ->
            val testFixturesCompilation = target.testFixturesCompilation
            val mainCompilation = target.mainCompilation
            if (testFixturesCompilation != null && mainCompilation != null) {
                testFixturesCompilation.associateWith(mainCompilation)
            }
        }
    }
}
The
targets
is custom so it is not deprecated, the problem is the compilation itself
If I pick the original
targets
in the KMP extension, as you can see in the popup, it is exposing
KotlinCompilation<KotlinCommonOptionsDeprecated /* = KotlinCommonOptions */>?
, I cannot find the alternative to this.
e
KotlinJvmProjectExtension
doesn't show any warnings for me
j
I can do it only on JVM, probably I will do that, but I don't know why on JVM it is not deprecated but it is on KMP, it is a bit weird
Additionally, it is not working right now on KMP too, but I was doing this too:
Copy code
configure<KotlinProjectExtension> {
    sourceSets.maybeCreate(TEST_INTEGRATION)
    targets.forEach { target ->
        target.configureAdditionalTestCompilations(TEST_INTEGRATION)
    }
}
testIntegration.configure {
    it.dependencies {
        implementation(project)
        if (isTestFixturesFullEnabled.get()) {
            implementation(project.dependencies.testFixtures(project))
        }
    }
}
My idea was to extend that to support KMP in the future, but looks like the configuration will be totally different in the future only for KMP
it is deprecated too on
KotlinSingleTargetExtension
, so I guess the only way is move the config to JVM and wait for the KMP config
I have changed the code to use
KotlinWithJavaTarget
and I am still getting the common deprecated API 🤔
Copy code
private fun KotlinWithJavaTarget<*, *>.compilation(name: String): KotlinWithJavaCompilation<out KotlinCommonOptions, out KotlinCommonCompilerOptions>? =
    compilations.findByName(name)
t
Kotlin*Options
are deprecated. It is not easy to remove a deprecated generic, so I will propose to suppress deprecation in this particular case
👍 1