[Gradle] Bump minimal supported AGP version to 7.1.3

^KT-62939 Fixed
This commit is contained in:
Yahor Berdnikau
2023-11-11 13:23:47 +01:00
committed by Space Team
parent f4d088a886
commit 6eca282e9a
27 changed files with 189 additions and 371 deletions
@@ -16,14 +16,6 @@ dependencies {
commonApi(project(":kotlin-tooling-core"))
commonCompileOnly(project(":kotlin-gradle-compiler-types"))
commonCompileOnly("com.android.tools.build:gradle-api:4.2.2") {
// Without it - Gradle dependency resolution fails with unexpected error
// Caused by: java.lang.IllegalStateException: Unexpected parent dependency id 131. Seen ids: [129, 2, 130, 9, 10, 138, 11, 139, 140, 14, 153, 154, 155, 156, 157, 158, 161, 164, 177, 178, 51, 179, 52, 180, 53, 54, 55, 183, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 195, 68, 200, 201, 202, 203, 206, 211, 212, 215, 222, 223, 224, 231, 232, 105, 233, 106, 107, 108, 109, 110, 111, 112, 113, 114, 242, 115, 243, 116, 244, 117, 118, 119, 120, 121, 122]
// at org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResultsBuilder.deserialize(TransientConfigurationResultsBuilder.java:171)
// at org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResultsBuilder.lambda$load$5(TransientConfigurationResultsBuilder.java:117)
// Could be reproduced by running `:kotlin-gradle-plugin-api:gPFFPMP` task
isTransitive = false
}
embedded(project(":kotlin-gradle-compiler-types")) { isTransitive = false }
}
@@ -444,8 +444,6 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
@DisplayName("KT-57959: should be possible to configure module name in MPP/android")
@GradleAndroidTest
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_0)
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_70)
@AndroidGradlePluginTests
@Disabled("DSL was demoted to 'internal'; Design is planned for 2.0")
fun mppAndroidModuleName(
@@ -19,7 +19,7 @@ import java.nio.file.Path
import kotlin.io.path.readText
import kotlin.test.fail
@GradleTestVersions(minVersion = TestVersions.Gradle.G_8_1)
@GradleTestVersions(minVersion = TestVersions.Gradle.G_8_2)
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_82)
@AndroidGradlePluginTests
class ExternalAndroidTargetIT : KGPBaseTest() {
@@ -194,7 +194,6 @@ open class Kapt3AndroidExternalIT : Kapt3BaseIT() {
@DisplayName("kapt works with androidx")
@GradleAndroidTest
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_42, maxVersion = TestVersions.AGP.AGP_42)
fun testDatabindingWithAndroidX(
gradleVersion: GradleVersion,
agpVersion: String,
@@ -8,10 +8,6 @@ package org.jetbrains.kotlin.gradle.android
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.testbase.TestVersions.AGP.AGP_70
import org.jetbrains.kotlin.gradle.testbase.TestVersions.AGP.AGP_71
import org.jetbrains.kotlin.gradle.testbase.TestVersions.Gradle.G_7_1
import org.jetbrains.kotlin.gradle.testbase.TestVersions.Gradle.G_7_2
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.jetbrains.kotlin.gradle.util.replaceText
@@ -28,8 +24,6 @@ import kotlin.test.*
@DisplayName("kotlin-android with mpp")
@AndroidGradlePluginTests
@GradleTestVersions(minVersion = G_7_1)
@AndroidTestVersions(minVersion = AGP_70)
class KotlinAndroidMppIT : KGPBaseTest() {
@DisplayName("KotlinToolingMetadataArtifact is bundled into apk")
@@ -67,8 +61,6 @@ class KotlinAndroidMppIT : KGPBaseTest() {
}
}
@AndroidTestVersions(minVersion = AGP_71)
@GradleTestVersions(minVersion = G_7_2)
@DisplayName("mpp source sets are registered in AGP")
@GradleAndroidTest
fun testAndroidMppSourceSets(
@@ -133,8 +125,6 @@ class KotlinAndroidMppIT : KGPBaseTest() {
}
}
@AndroidTestVersions(minVersion = AGP_70)
@GradleTestVersions(minVersion = G_7_2)
@DisplayName("android mpp lib flavors publication can be configured")
@GradleAndroidTest
fun testMppAndroidLibFlavorsPublication(
@@ -266,17 +256,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
build("publish") {
listOf("fooBar", "fooBaz").forEach { flavorName ->
val flavor = flavorName.lowercase()
val flavorAttributes = if (AGPVersion.fromString(agpVersion) > AGPVersion.v7_0_0) {
arrayOf(
"foo" to flavorName,
"com.android.build.api.attributes.ProductFlavor:foo" to flavorName
)
} else {
arrayOf(
"foo" to flavorName
)
}
val flavorAttributes = arrayOf(
"foo" to flavorName,
"com.android.build.api.attributes.ProductFlavor:foo" to flavorName
)
assertFileExists(groupDir.resolve("lib-androidlib-$flavor/1.0/lib-androidlib-$flavor-1.0.aar"))
assertFileExists(groupDir.resolve("lib-androidlib-$flavor/1.0/lib-androidlib-$flavor-1.0-sources.jar"))
@@ -319,16 +302,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
listOf("fooBar", "fooBaz").forEach { flavorName ->
val flavor = flavorName.lowercase()
val flavorAttributes = if (AGPVersion.fromString(agpVersion) > AGPVersion.v7_0_0) {
arrayOf(
"foo" to flavorName,
"com.android.build.api.attributes.ProductFlavor:foo" to flavorName
)
} else {
arrayOf(
"foo" to flavorName
)
}
val flavorAttributes = arrayOf(
"foo" to flavorName,
"com.android.build.api.attributes.ProductFlavor:foo" to flavorName
)
listOf("-debug", "").forEach { buildType ->
assertFileExists(groupDir.resolve("lib-androidlib-$flavor$buildType/1.0/lib-androidlib-$flavor$buildType-1.0.aar"))
@@ -587,8 +564,6 @@ class KotlinAndroidMppIT : KGPBaseTest() {
}
}
@AndroidTestVersions(minVersion = AGP_70)
@GradleTestVersions(minVersion = G_7_2)
@DisplayName("KT-27714: custom attributes are copied to android compilation configurations")
@GradleAndroidTest
fun testCustomAttributesInAndroidTargets(
@@ -796,10 +771,9 @@ class KotlinAndroidMppIT : KGPBaseTest() {
}
}
// TODO: improve it via KT-63409
@DisplayName("produced artifacts are consumable by projects with various AGP versions")
@GradleAndroidTest
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_71)
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_2) // due AGP version limit ^
fun testAndroidMultiplatformPublicationAGPCompatibility(
gradleVersion: GradleVersion,
agpVersion: String,
@@ -822,30 +796,20 @@ class KotlinAndroidMppIT : KGPBaseTest() {
}
}
val checkedConsumerAGPVersions = AGPVersion.testedVersions
.filter { version -> version >= AGPVersion.fromString(TestVersions.AGP.AGP_42) }
.filter { version -> version < AGPVersion.fromString(TestVersions.AGP.MAX_SUPPORTED) }
.map { it.toString() }
val checkedConsumerAGPVersions = TestVersions.AgpCompatibilityMatrix
.values()
.filter { agp -> AGPVersion.fromString(agp.version) < AGPVersion.fromString(TestVersions.AGP.MAX_SUPPORTED) }
checkedConsumerAGPVersions.forEach { consumerAgpVersion ->
val agpTestVersion = TestVersions.AgpCompatibilityMatrix.values().find { it.version == consumerAgpVersion }
?: fail("AGP version $consumerAgpVersion is not defined in TestVersions.AGP!")
val consumerGradleVersion = when {
gradleVersion < agpTestVersion.minSupportedGradleVersion -> agpTestVersion.minSupportedGradleVersion
gradleVersion > agpTestVersion.maxSupportedGradleVersion -> agpTestVersion.maxSupportedGradleVersion
else -> gradleVersion
}
println("Testing compatibility for AGP consumer version $consumerAgpVersion on Gradle ${consumerGradleVersion.version} (Producer: $agpVersion)")
println(
"Testing compatibility for AGP consumer version $consumerAgpVersion on Gradle" +
" ${consumerAgpVersion.minSupportedGradleVersion} (Producer: $agpVersion)"
)
project(
"new-mpp-android-agp-compatibility",
consumerGradleVersion,
buildOptions = defaultBuildOptions.copy(androidVersion = consumerAgpVersion)
.suppressDeprecationWarningsOn(
"AGP relies on FileTrees for ignoring empty directories when using @SkipWhenEmpty which has been deprecated."
) { options ->
consumerGradleVersion >= GradleVersion.version(TestVersions.Gradle.G_7_4) && AGPVersion.fromString(options.safeAndroidVersion) < AGPVersion.v7_1_0
},
buildJdk = jdkVersion.location,
consumerAgpVersion.minSupportedGradleVersion,
buildOptions = defaultBuildOptions.copy(androidVersion = consumerAgpVersion.version),
buildJdk = File(System.getProperty("jdk${consumerAgpVersion.requiredJdkVersion.majorVersion}Home")),
localRepoDir = tempDir
) {
/*
@@ -860,7 +824,10 @@ class KotlinAndroidMppIT : KGPBaseTest() {
*/
build(":plainAndroidConsumer:assemble")
}
println("Successfully tested compatibility for AGP consumer version $consumerAgpVersion on Gradle ${consumerGradleVersion.version} (Producer: $agpVersion)")
println(
"Successfully tested compatibility for AGP consumer version $consumerAgpVersion on Gradle" +
" ${consumerAgpVersion.minSupportedGradleVersion} (Producer: $agpVersion)"
)
}
}
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.gradle.android
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.junit.jupiter.api.DisplayName
import kotlin.test.assertNull
@@ -17,18 +16,11 @@ class MultiplatformAndroidSourceSetLayoutV2IT : KGPBaseTest() {
@GradleAndroidTest
@DisplayName("test Android project with flavors")
@AndroidTestVersions(minVersion = "7.0.4")
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_0) // due AGP version limit ^
fun testProjectWithFlavors(gradleVersion: GradleVersion, agpVersion: String, jdkVersion: JdkVersions.ProvidedJdk) {
project(
"multiplatformAndroidSourceSetLayout2",
gradleVersion,
defaultBuildOptions.copy(androidVersion = agpVersion)
.suppressDeprecationWarningsOn(
"AGP relies on FileTrees for ignoring empty directories when using @SkipWhenEmpty which has been deprecated."
) { options ->
gradleVersion >= GradleVersion.version(TestVersions.Gradle.G_7_4) && AGPVersion.fromString(options.safeAndroidVersion) < AGPVersion.v7_1_0
},
defaultBuildOptions.copy(androidVersion = agpVersion),
buildJdk = jdkVersion.location
) {
build("test") {
@@ -27,10 +27,11 @@ import java.lang.Boolean as RefBoolean
// Tests are not working with AGP >= 7.1.0. See KT-57351 for details
@Ignore("TODO: update this test via KT-58298")
class AndroidAndJavaConsumeMppLibBuiltByGradle7IT : AndroidAndJavaConsumeMppLibIT() {
override val producerAgpVersion: AGPVersion = AGPVersion.v7_0_0
override val producerAgpVersion: AGPVersion = AGPVersion.v7_1_0
override val producerGradleVersion: GradleVersionRequired = GradleVersionRequired.InRange(
TestVersions.Gradle.G_7_0,
TestVersions.Gradle.G_7_1,
TestVersions.Gradle.G_7_6
)
}
@@ -67,8 +68,7 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
@Parameterized.Parameters(name = "Consumer(AGP={3}, Gradle={4}), flavors={0}, debugOnly={1}, published={2}")
fun testCases(): List<Array<Any>> {
val consumers = listOf(
AGPVersion.v4_2_0 to GradleVersionRequired.Exact(TestVersions.Gradle.G_6_9),
AGPVersion.v7_0_0 to GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_6),
AGPVersion.v7_1_0 to GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_6),
)
val buildParams = listOf(
/* useFlavors, isAndroidPublishDebugOnly, isPublishedLibrary */
@@ -120,16 +120,12 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
val producerBuildOptions: BuildOptions
dependencyProject = Project("new-mpp-android", producerGradleVersion, minLogLevel = LogLevel.INFO).apply {
val usedProducerGradleVersion = chooseWrapperVersionOrFinishTest()
chooseWrapperVersionOrFinishTest()
producerBuildOptions = defaultBuildOptions().copy(
javaHome = jdk11Home,
androidHome = KtTestUtil.findAndroidSdk(),
androidGradlePluginVersion = producerAgpVersion,
).suppressDeprecationWarningsOn(
"AGP relies on FileTrees for ignoring empty directories when using @SkipWhenEmpty which has been deprecated (Gradle 7.4)"
) { options ->
GradleVersion.version(usedProducerGradleVersion) >= GradleVersion.version(TestVersions.Gradle.G_7_4) && options.safeAndroidGradlePluginVersion < AGPVersion.v7_1_0
}
)
producerBuildOptions.androidHome?.let { acceptAndroidSdkLicenses(it) }
projectDir.deleteRecursively()
setupWorkingDir()
@@ -296,7 +292,11 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
"AGP uses deprecated IncrementalTaskInputs (Gradle 7.5)"
) { options ->
// looks a bit messy :/
(!isPublishedLibrary && (withKotlinVersion != null || options.safeAndroidGradlePluginVersion >= AGPVersion.v7_0_0) || isPublishedLibrary && withKotlinVersion == oldKotlinVersion) &&
(!isPublishedLibrary &&
(withKotlinVersion != null || options.safeAndroidGradlePluginVersion >= AGPVersion.v7_1_0) ||
isPublishedLibrary &&
withKotlinVersion == oldKotlinVersion
) &&
GradleVersion.version(usedConsumerGradleVersion) >= GradleVersion.version(TestVersions.Gradle.G_7_5) &&
options.safeAndroidGradlePluginVersion < AGPVersion.v7_3_0
}
@@ -308,7 +308,7 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
* This test asserts the existing incorrect behavior for older Gradle versions
* in the absence of the Kotlin Gradle plugin, in order to detect unintentional changes
*/
val expectedVariant = if (consumerAgpVersion < AGPVersion.v7_0_0 && withKotlinVersion == null && !isPublishedLibrary) {
val expectedVariant = if (withKotlinVersion == null && !isPublishedLibrary) {
"jvmLibApiElements"
} else expected
@@ -375,7 +375,7 @@ class ResolvedVariantChecker {
}
}
fun getResolvedVariantsBatch(
private fun getResolvedVariantsBatch(
project: BaseGradleIT.Project,
requests: Iterable<ResolvedVariantRequest>,
buildOptions: BaseGradleIT.BuildOptions = project.testCase.defaultBuildOptions()
@@ -354,8 +354,6 @@ class MppCompositeBuildIT : KGPBaseTest() {
}
}
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_1)
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_70)
@GradleAndroidTest
fun `test - sample6-KT-56712-umbrella-composite`(
gradleVersion: GradleVersion, agpVersion: String, jdkVersion: JdkVersions.ProvidedJdk,
@@ -42,17 +42,15 @@ interface TestVersions {
}
object AGP {
const val AGP_42 = "4.2.2"
const val AGP_70 = "7.0.4"
const val AGP_71 = "7.1.3"
const val AGP_72 = "7.2.2"
const val AGP_73 = "7.3.1"
const val AGP_74 = "7.4.2"
const val AGP_80 = "8.0.2"
const val AGP_81 = "8.1.0-rc01"
const val AGP_82 = "8.2.0-alpha13"
const val AGP_81 = "8.1.3"
const val AGP_82 = "8.2.0-rc03"
const val MIN_SUPPORTED = AGP_42 // KotlinAndroidPlugin.minimalSupportedAgpVersion
const val MIN_SUPPORTED = AGP_71 // KotlinAndroidPlugin.minimalSupportedAgpVersion
const val MAX_SUPPORTED = AGP_81 // Update once Gradle MAX_SUPPORTED version will be bumped
}
@@ -62,15 +60,13 @@ interface TestVersions {
val maxSupportedGradleVersion: GradleVersion,
val requiredJdkVersion: JavaVersion
) {
AGP_42(AGP.AGP_42, GradleVersion.version(Gradle.MIN_SUPPORTED), GradleVersion.version(Gradle.G_6_9), JavaVersion.VERSION_1_8),
AGP_70(AGP.AGP_70, GradleVersion.version(Gradle.G_7_0), GradleVersion.version(Gradle.G_7_4), JavaVersion.VERSION_11),
AGP_71(AGP.AGP_71, GradleVersion.version(Gradle.G_7_2), GradleVersion.version(Gradle.G_7_4), JavaVersion.VERSION_11),
AGP_72(AGP.AGP_72, GradleVersion.version(Gradle.G_7_3), GradleVersion.version(Gradle.G_7_4), JavaVersion.VERSION_11),
AGP_73(AGP.AGP_73, GradleVersion.version(Gradle.G_7_4), GradleVersion.version(Gradle.G_7_5), JavaVersion.VERSION_11),
AGP_74(AGP.AGP_74, GradleVersion.version(Gradle.G_7_5), GradleVersion.version(Gradle.G_7_6), JavaVersion.VERSION_11),
AGP_80(AGP.AGP_80, GradleVersion.version(Gradle.G_8_0), GradleVersion.version(Gradle.G_8_0), JavaVersion.VERSION_17),
AGP_81(AGP.AGP_81, GradleVersion.version(Gradle.G_8_1), GradleVersion.version(Gradle.G_8_1), JavaVersion.VERSION_17),
AGP_82(AGP.AGP_82, GradleVersion.version(Gradle.G_8_1), GradleVersion.version(Gradle.G_8_3), JavaVersion.VERSION_17),
AGP_82(AGP.AGP_82, GradleVersion.version(Gradle.G_8_2), GradleVersion.version(Gradle.G_8_3), JavaVersion.VERSION_17),
;
}
@@ -177,14 +177,13 @@ class GradleAndAgpArgumentsProvider : GradleArgumentsProvider() {
gradleVersions
.filter { it in agpVersion.minSupportedGradleVersion..agpVersion.maxSupportedGradleVersion }
.ifEmpty {
// Falling back to the minimal supported Gradle version for this AGP version
listOf(agpVersion.minSupportedGradleVersion)
}
.map {
AgpTestArguments(it, agpVersion.version, providedJdk)
}
.also {
require(it.isNotEmpty()) {
"Could not find suitable Gradle version for AGP $agpVersion version!"
}
}
}
.asSequence()
.map {
@@ -18,14 +18,7 @@ class AGPVersion private constructor(private val versionNumber: VersionNumber) {
fun fromString(versionString: String): AGPVersion =
AGPVersion(VersionNumber.parse(versionString))
val v4_1_0 = fromString("4.1.3")
val v4_2_0 = fromString("4.2.2")
val v7_0_0 = fromString("7.0.4")
val v7_1_0 = fromString("7.1.3")
val v7_2_2 = fromString("7.2.2")
val v7_3_0 = fromString("7.3.1")
val v7_4_0 = fromString("7.4.2")
val testedVersions = listOf(v4_1_0, v4_2_0, v7_0_0, v7_1_0, v7_2_2, v7_3_0, v7_4_0)
}
}
@@ -21,7 +21,7 @@ kotlin {
compileSdk = 33
namespace = "org.jetbrains.sample"
withAndroidTestOnJvm()
withAndroidTestOnJvm {}
sourceSets.getByName("androidTestOnJvm").dependencies {
implementation("junit:junit:4.13.2")
}
@@ -17,7 +17,7 @@ kotlin {
compileSdk = 33
namespace = "org.jetbrains.sample"
withAndroidTestOnJvm()
withAndroidTestOnJvm {}
sourceSets.getByName("androidTestOnJvm").dependencies {
implementation("junit:junit:4.13.2")
}
@@ -1,13 +1,16 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.kapt'
}
android {
compileSdkVersion 24
compileSdkVersion 34
namespace = "com.example.databinding"
defaultConfig {
applicationId "com.example.databinding"
minSdkVersion 21
targetSdkVersion 24
targetSdkVersion 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -24,6 +27,5 @@ android {
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
@@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.databinding">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application />
</manifest>
</manifest>
@@ -1,26 +1,8 @@
import org.gradle.util.VersionNumber
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:$android_tools_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
}
}
}
@@ -1,2 +1,4 @@
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
kotlin.jvm.target.validation.mode=warning
@@ -67,25 +67,11 @@ dependencies {
commonCompileOnly(project(":kotlin-compiler-runner-unshaded"))
commonCompileOnly(project(":kotlin-gradle-statistics"))
commonCompileOnly(project(":kotlin-gradle-build-metrics"))
commonCompileOnly("com.android.tools.build:gradle:4.2.2") {
exclude("org.ow2.asm")
exclude("net.sf.proguard")
exclude("net.sf.jopt-simple")
exclude("com.squareup")
exclude("com.google.crypto.tink")
exclude("com.google.guava")
exclude("com.google.protobuf")
exclude("com.google.testing.platform")
exclude("com.android.tools.lint")
exclude("androidx.databinding")
exclude("com.android.tools.analytics-library")
exclude("com.android.tools.build.jetifier")
exclude("com.android.tools.build", "transform-api")
exclude("com.android.tools.build", "builder-test-api")
exclude("com.android.tools.build", "bundletool")
exclude("com.android.tools.build", "aaptcompiler")
exclude("com.android.tools.build", "aapt2-proto")
}
commonCompileOnly(libs.android.gradle.plugin.gradle.api) { isTransitive = false }
commonCompileOnly(libs.android.gradle.plugin.gradle) { isTransitive = false }
commonCompileOnly(libs.android.gradle.plugin.builder) { isTransitive = false }
commonCompileOnly(libs.android.gradle.plugin.builder.model) { isTransitive = false }
commonCompileOnly(libs.android.tools.common) { isTransitive = false }
commonCompileOnly(intellijPlatformUtil())
commonCompileOnly(commonDependency("org.jetbrains.teamcity:serviceMessages"))
commonCompileOnly(libs.gradle.enterprise.gradlePlugin)
@@ -56,7 +56,7 @@ internal open class KotlinAndroidPlugin(
}
companion object {
private val minimalSupportedAgpVersion = AndroidGradlePluginVersion(4, 2, 2)
private val minimalSupportedAgpVersion = AndroidGradlePluginVersion(7, 1, 3)
fun androidTargetHandler(): AndroidProjectHandler {
val tasksProvider = KotlinTasksProvider()
val androidGradlePluginVersion = AndroidGradlePluginVersion.currentOrNull
@@ -186,6 +186,11 @@ abstract class DefaultKotlinBasePlugin : KotlinBasePlugin {
ConfigurationCacheStartParameterAccessor.Factory::class,
DefaultConfigurationCacheStartParameterAccessorVariantFactory()
)
factories.putIfAbsent(
SourceSetCompatibilityHelper.SourceSetCompatibilityHelperVariantFactory::class,
DefaultSourceSetCompatibilityHelperVariantFactory()
)
}
protected fun setupAttributeMatchingStrategy(
@@ -6,17 +6,9 @@
package org.jetbrains.kotlin.gradle.plugin
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
import org.gradle.api.attributes.*
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.bundling.Zip
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.runKotlinCompilationSideEffects
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
@@ -24,11 +16,7 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetAttribute
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.targets.js.toAttribute
import org.jetbrains.kotlin.gradle.targets.runKotlinTargetSideEffects
import org.jetbrains.kotlin.gradle.tasks.registerTask
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.full.memberProperties
interface KotlinTargetConfigurator<KotlinTargetType : KotlinTarget> {
fun configureTarget(
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.plugin.internal
import org.gradle.api.tasks.SourceSet
import org.jetbrains.kotlin.gradle.plugin.VariantImplementationFactories
interface SourceSetCompatibilityHelper {
fun getCompileConfigurationName(sourceSet: SourceSet): String?
fun getRuntimeConfigurationName(sourceSet: SourceSet): String?
interface SourceSetCompatibilityHelperVariantFactory : VariantImplementationFactories.VariantImplementationFactory {
fun getInstance(): SourceSetCompatibilityHelper
}
}
internal class DefaultSourceSetCompatibilityHelperVariantFactory : SourceSetCompatibilityHelper.SourceSetCompatibilityHelperVariantFactory {
override fun getInstance(): SourceSetCompatibilityHelper = DefaultSourceSetCompatibilityHelper()
}
internal class DefaultSourceSetCompatibilityHelper() : SourceSetCompatibilityHelper {
override fun getCompileConfigurationName(sourceSet: SourceSet): String? = null
override fun getRuntimeConfigurationName(sourceSet: SourceSet): String? = null
}
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.Stage.AfterFinal
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnostic
import org.jetbrains.kotlin.gradle.plugin.internal.JavaSourceSetsAccessor
import org.jetbrains.kotlin.gradle.plugin.internal.SourceSetCompatibilityHelper
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
@@ -41,10 +42,8 @@ import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.gradle.utils.Future
import org.jetbrains.kotlin.gradle.utils.findAppliedAndroidPluginIdOrNull
import org.jetbrains.kotlin.gradle.utils.future
import org.jetbrains.kotlin.utils.addToStdlib.cast
import java.util.concurrent.Callable
import javax.inject.Inject
import kotlin.reflect.full.functions
abstract class KotlinJvmTarget @Inject constructor(
project: Project,
@@ -168,8 +167,11 @@ abstract class KotlinJvmTarget @Inject constructor(
}
project.launchInStage(AfterFinaliseDsl) {
val sourceSetCompatibilityHelper = project
.variantImplementationFactory<SourceSetCompatibilityHelper.SourceSetCompatibilityHelperVariantFactory>()
.getInstance()
javaSourceSets.all { javaSourceSet ->
copyUserDefinedAttributesToJavaConfigurations(javaSourceSet)
copyUserDefinedAttributesToJavaConfigurations(javaSourceSet, sourceSetCompatibilityHelper)
}
}
@@ -259,12 +261,13 @@ abstract class KotlinJvmTarget @Inject constructor(
// Add the Java source set dependencies to the Kotlin compilation compile & runtime configurations:
val sourceSetCompatibilityHelper = project
.variantImplementationFactory<SourceSetCompatibilityHelper.SourceSetCompatibilityHelperVariantFactory>()
.getInstance()
val compileConfigurationName = if (areRuntimeOrCompileConfigurationsAvailable()) {
javaSourceSet::class
.functions
.find { it.name == "getCompileConfigurationName" }
?.call(javaSourceSet)
?.cast<String>()
sourceSetCompatibilityHelper
.getCompileConfigurationName(javaSourceSet)
?.takeIf { project.configurations.findByName(it) != null }
} else null
@@ -278,11 +281,8 @@ abstract class KotlinJvmTarget @Inject constructor(
}
val runtimeConfigurationName = if (areRuntimeOrCompileConfigurationsAvailable()) {
javaSourceSet::class
.functions
.find { it.name == "getRuntimeConfigurationName" }
?.call(javaSourceSet)
?.cast<String>()
sourceSetCompatibilityHelper
.getRuntimeConfigurationName(javaSourceSet)
?.takeIf { project.configurations.findByName(it) != null }
} else null
@@ -296,22 +296,19 @@ abstract class KotlinJvmTarget @Inject constructor(
}
}
private fun copyUserDefinedAttributesToJavaConfigurations(javaSourceSet: SourceSet) {
private fun copyUserDefinedAttributesToJavaConfigurations(
javaSourceSet: SourceSet,
sourceSetCompatibilityHelper: SourceSetCompatibilityHelper
) {
val compileConfigurationName = if (areRuntimeOrCompileConfigurationsAvailable()) {
javaSourceSet::class
.functions
.find { it.name == "getCompileConfigurationName" }
?.call(javaSourceSet)
?.cast<String>()
sourceSetCompatibilityHelper
.getCompileConfigurationName(javaSourceSet)
?.takeIf { project.configurations.findByName(it) != null }
} else null
val runtimeConfigurationName = if (areRuntimeOrCompileConfigurationsAvailable()) {
javaSourceSet::class
.functions
.find { it.name == "getRuntimeConfigurationName" }
?.call(javaSourceSet)
?.cast<String>()
sourceSetCompatibilityHelper
.getRuntimeConfigurationName(javaSourceSet)
?.takeIf { project.configurations.findByName(it) != null }
} else null
@@ -10,7 +10,6 @@ import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.model.ObjectFactory
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.jetbrains.kotlin.gradle.plugin.internal.*
import org.jetbrains.kotlin.gradle.plugin.internal.JavaSourceSetsAccessorG6
@@ -161,4 +160,6 @@ private fun Project.registerVariantImplementations() {
factories[UnameExecutor.UnameExecutorVariantFactory::class] =
UnameExecutorG6.UnameExecutorVariantFactoryG6()
factories[ConfigurationCacheStartParameterAccessor.Factory::class] = ConfigurationCacheStartParameterAccessorG6.Factory()
factories[SourceSetCompatibilityHelper.SourceSetCompatibilityHelperVariantFactory::class] =
SourceSetCompatibilityHelperG6VariantFactory()
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.plugin.internal
import org.gradle.api.tasks.SourceSet
internal class SourceSetCompatibilityHelperG6 : SourceSetCompatibilityHelper {
override fun getCompileConfigurationName(sourceSet: SourceSet): String {
@Suppress("DEPRECATION")
return sourceSet.compileConfigurationName
}
override fun getRuntimeConfigurationName(sourceSet: SourceSet): String {
@Suppress("DEPRECATION")
return sourceSet.runtimeConfigurationName
}
}
internal class SourceSetCompatibilityHelperG6VariantFactory : SourceSetCompatibilityHelper.SourceSetCompatibilityHelperVariantFactory {
override fun getInstance(): SourceSetCompatibilityHelper = SourceSetCompatibilityHelperG6()
}