Browse Source

Merge pull request #399 from JetBrains/replace-androidx-artifacts

Gradle plugin. Replace 'androidx.compose' artifacts by 'org.jetbrains.compose' artifacts.
pull/405/head
Igor Demin 4 years ago committed by GitHub
parent
commit
c7a4494269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      gradle-plugins/buildSrc/build.gradle.kts
  2. 67
      gradle-plugins/buildSrc/src/main/kotlin/printAllAndroidxReplacements.kt
  3. 4
      gradle-plugins/compose/build.gradle.kts
  4. 49
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt
  5. 2
      gradle-plugins/gradle/wrapper/gradle-wrapper.properties

2
gradle-plugins/buildSrc/build.gradle.kts

@ -9,4 +9,6 @@ repositories {
dependencies { dependencies {
compileOnly(gradleApi()) compileOnly(gradleApi())
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))
implementation("io.ktor:ktor-client-core:1.5.1")
implementation("io.ktor:ktor-client-cio:1.5.1")
} }

67
gradle-plugins/buildSrc/src/main/kotlin/printAllAndroidxReplacements.kt

@ -0,0 +1,67 @@
import io.ktor.client.*
import io.ktor.client.request.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
import org.gradle.api.Project
private const val libsRepo = "https://maven.pkg.jetbrains.space/public/p/compose/dev/org/jetbrains/compose/"
private val exceptions = listOf(
"desktop:desktop",
"compose-full",
"compose-gradle-plugin"
)
fun Project.printAllAndroidxReplacements() = runBlocking {
val version = BuildProperties.composeVersion(project)
HttpClient().use { client ->
client
.allRecursiveFolders(libsRepo)
.map { it.removePrefix(libsRepo).removeSuffix("/") }
.filter { it.endsWith(version) }
.map { it.removeSuffix(version).removeSuffix("/") }
.map { it.replace("/", ":") }
.filter { !it.endsWith("-android") }
.filter { !it.endsWith("-android-debug") }
.filter { !it.endsWith("-android-release") }
.filter { !it.endsWith("-metadata") }
.filter { !it.endsWith("-desktop") }
.filter { !it.contains("-jvm") }
.filter { !exceptions.contains(it) }
.collect {
require(isMavenCoordsValid(it)) {
"module name isn't valid: $it"
}
println("it.replaceAndroidx(\"androidx.compose.$it\", \"org.jetbrains.compose.$it\")")
}
}
}
private fun isMavenCoordsValid(coords: String) = coords.count { it == ':' } == 1
private fun HttpClient.allRecursiveFolders(
url: String
): Flow<String> = flow {
require(url.endsWith("/"))
val response = get<String>(url)
val folders = parseFolders(response)
for (folder in folders) {
emit("$url$folder/")
}
for (folder in folders.filter(String::isMavenPart)) {
allRecursiveFolders("$url$folder/").collect(::emit)
}
}
private fun parseFolders(
htmlResponse: String
): Sequence<String> = Regex("title=\"(.*?)\"")
.findAll(htmlResponse)
.map { it.groupValues[1] }
.filter { it.endsWith("/") && it != "../" }
.map { it.removeSuffix("/") }
private fun String.isMavenPart() = all { it.isLetterOrDigit() || it == '-' }

4
gradle-plugins/compose/build.gradle.kts

@ -101,3 +101,7 @@ fun Test.configureTest(gradleVersion: String) {
tasks.named("check") { tasks.named("check") {
dependsOn(testMinGradleVersion) dependsOn(testMinGradleVersion)
} }
task("printAllAndroidxReplacements") {
doLast { printAllAndroidxReplacements() }
}

49
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt

@ -4,6 +4,7 @@ package org.jetbrains.compose
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.ComponentModuleMetadataHandler
import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.plugins.ExtensionAware import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.DesktopExtension
@ -42,6 +43,54 @@ class ComposePlugin : Plugin<Project> {
) )
} }
fun ComponentModuleMetadataHandler.replaceAndroidx(original: String, replacement: String) {
module(original) {
it.replacedBy(replacement, "org.jetbrains.compose isn't compatible with androidx.compose, because it is the same library published with different maven coordinates")
}
}
project.dependencies.modules {
// Replace 'androidx.compose' artifacts by 'org.jetbrains.compose' artifacts.
// It is needed, because 'org.jetbrains.compose' artifacts are the same artifacts as 'androidx.compose'
// (but with different version).
// And Gradle will throw an error when it cannot determine which class from which artifact should it use.
//
// Note that we don't provide a configuration parameter to disable dependency replacement,
// because without replacement, gradle will fail anyway because classpath contains two incompatible artifacts.
//
// We should define all replacements, even for transient dependencies.
// For example, a library can depend on androidx.compose.foundation:foundation-layout
//
// List of all org.jetbrains.compose libraries is here:
// https://maven.pkg.jetbrains.space/public/p/compose/dev/org/jetbrains/compose/
//
// (use ./gradle printAllAndroidxReplacements to know what dependencies should be here)
//
// It is temporarily solution until we will be publishing all MPP artifacts in Google Maven repository.
// Or align versions with androidx artifacts and point MPP-android artifacts to androidx artifacts (is it possible?)
it.replaceAndroidx("androidx.compose.animation:animation", "org.jetbrains.compose.animation:animation")
it.replaceAndroidx("androidx.compose.animation:animation-core", "org.jetbrains.compose.animation:animation-core")
it.replaceAndroidx("androidx.compose.compiler:compiler", "org.jetbrains.compose.compiler:compiler")
it.replaceAndroidx("androidx.compose.compiler:compiler-hosted", "org.jetbrains.compose.compiler:compiler-hosted")
it.replaceAndroidx("androidx.compose.foundation:foundation", "org.jetbrains.compose.foundation:foundation")
it.replaceAndroidx("androidx.compose.foundation:foundation-layout", "org.jetbrains.compose.foundation:foundation-layout")
it.replaceAndroidx("androidx.compose.material:material", "org.jetbrains.compose.material:material")
it.replaceAndroidx("androidx.compose.material:material-icons-core", "org.jetbrains.compose.material:material-icons-core")
it.replaceAndroidx("androidx.compose.material:material-icons-extended", "org.jetbrains.compose.material:material-icons-extended")
it.replaceAndroidx("androidx.compose.material:material-ripple", "org.jetbrains.compose.material:material-ripple")
it.replaceAndroidx("androidx.compose.runtime:runtime", "org.jetbrains.compose.runtime:runtime")
it.replaceAndroidx("androidx.compose.runtime:runtime-saveable", "org.jetbrains.compose.runtime:runtime-saveable")
it.replaceAndroidx("androidx.compose.ui:ui", "org.jetbrains.compose.ui:ui")
it.replaceAndroidx("androidx.compose.ui:ui-geometry", "org.jetbrains.compose.ui:ui-geometry")
it.replaceAndroidx("androidx.compose.ui:ui-graphics", "org.jetbrains.compose.ui:ui-graphics")
it.replaceAndroidx("androidx.compose.ui:ui-test", "org.jetbrains.compose.ui:ui-test")
it.replaceAndroidx("androidx.compose.ui:ui-test-junit4", "org.jetbrains.compose.ui:ui-test-junit4")
it.replaceAndroidx("androidx.compose.ui:ui-text", "org.jetbrains.compose.ui:ui-text")
it.replaceAndroidx("androidx.compose.ui:ui-unit", "org.jetbrains.compose.ui:ui-unit")
it.replaceAndroidx("androidx.compose.ui:ui-util", "org.jetbrains.compose.ui:ui-util")
}
project.tasks.withType(KotlinCompile::class.java) { project.tasks.withType(KotlinCompile::class.java) {
it.kotlinOptions.apply { it.kotlinOptions.apply {
jvmTarget = "1.8".takeIf { jvmTarget.toDouble() < 1.8 } ?: jvmTarget jvmTarget = "1.8".takeIf { jvmTarget.toDouble() < 1.8 } ?: jvmTarget

2
gradle-plugins/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

Loading…
Cancel
Save