Add an IT for publication of multiplatform resources in Android target
^KT-65540
This commit is contained in:
committed by
Space Team
parent
a2989a3711
commit
bba39dd4fe
+12
@@ -46,6 +46,18 @@ import java.util.zip.GZIPInputStream
|
|||||||
// Set this to true if you want to dump all bytecode (test will fail in this case)
|
// Set this to true if you want to dump all bytecode (test will fail in this case)
|
||||||
private val DUMP_ALL = System.getProperty("comparison.dump.all") == "true"
|
private val DUMP_ALL = System.getProperty("comparison.dump.all") == "true"
|
||||||
|
|
||||||
|
fun assertEqualDirectoriesIgnoringDotFiles(
|
||||||
|
expected: File,
|
||||||
|
actual: File,
|
||||||
|
forgiveOtherExtraFiles: Boolean,
|
||||||
|
) = assertEqualDirectories(
|
||||||
|
expected,
|
||||||
|
actual,
|
||||||
|
forgiveExtraFiles = forgiveOtherExtraFiles,
|
||||||
|
// e.g. ignore .DS_Store on macOS
|
||||||
|
filter = { !it.name.startsWith(".") },
|
||||||
|
)
|
||||||
|
|
||||||
fun assertEqualDirectories(
|
fun assertEqualDirectories(
|
||||||
expected: File,
|
expected: File,
|
||||||
actual: File,
|
actual: File,
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2024 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.mpp.resources
|
||||||
|
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
|
import org.jetbrains.kotlin.incremental.testingUtils.assertEqualDirectoriesIgnoringDotFiles
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
@MppGradlePluginTests
|
||||||
|
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_73)
|
||||||
|
@DisplayName("Test multiplatform resources consumption and publication in androidTarget()")
|
||||||
|
class AndroidMultiplatformResourcesIT : KGPBaseTest() {
|
||||||
|
|
||||||
|
@DisplayName("Multiplatform resources consumption from self, published and project dependencies for Android target")
|
||||||
|
@GradleAndroidTest
|
||||||
|
fun testConsumption(
|
||||||
|
gradleVersion: GradleVersion,
|
||||||
|
androidVersion: String,
|
||||||
|
providedJdk: JdkVersions.ProvidedJdk,
|
||||||
|
) {
|
||||||
|
publishDependencyProject(
|
||||||
|
gradleVersion,
|
||||||
|
providedJdk,
|
||||||
|
androidVersion
|
||||||
|
) { repositoryRoot ->
|
||||||
|
project(
|
||||||
|
"multiplatformResources/android",
|
||||||
|
gradleVersion,
|
||||||
|
buildJdk = providedJdk.location,
|
||||||
|
localRepoDir = repositoryRoot,
|
||||||
|
) {
|
||||||
|
settingsGradleKts.append(
|
||||||
|
"""
|
||||||
|
include(":consumer")
|
||||||
|
include(":projectDependency")
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
buildWithAGPVersion(
|
||||||
|
":consumer:zipApksForDebug",
|
||||||
|
androidVersion,
|
||||||
|
defaultBuildOptions,
|
||||||
|
)
|
||||||
|
val apkPath = projectPath.resolve("consumer/build/outputs/apk/debug/consumer-debug.apk")
|
||||||
|
assertAssetsMatchReference(apkPath)
|
||||||
|
assertEmbeddedResourcesMatchReference(apkPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TestProject.assertAssetsMatchReference(
|
||||||
|
apkPath: Path,
|
||||||
|
) {
|
||||||
|
val assetsPath = projectPath.resolve("assetsInApk")
|
||||||
|
unzip(
|
||||||
|
apkPath,
|
||||||
|
outputDir = assetsPath,
|
||||||
|
filesStartingWith = "assets",
|
||||||
|
)
|
||||||
|
val referenceAssets = projectPath.resolve("reference/assets").toFile()
|
||||||
|
assertEqualDirectoriesIgnoringDotFiles(
|
||||||
|
expected = referenceAssets,
|
||||||
|
actual = assetsPath.toFile(),
|
||||||
|
forgiveOtherExtraFiles = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TestProject.assertEmbeddedResourcesMatchReference(
|
||||||
|
apkPath: Path,
|
||||||
|
) {
|
||||||
|
val resourcesPath = projectPath.resolve("resourcesInApk")
|
||||||
|
unzip(
|
||||||
|
apkPath,
|
||||||
|
outputDir = resourcesPath,
|
||||||
|
filesStartingWith = "embed",
|
||||||
|
)
|
||||||
|
val referenceResources = projectPath.resolve("reference/resources").toFile()
|
||||||
|
assertEqualDirectoriesIgnoringDotFiles(
|
||||||
|
expected = referenceResources,
|
||||||
|
actual = resourcesPath.toFile(),
|
||||||
|
forgiveOtherExtraFiles = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun publishDependencyProject(
|
||||||
|
gradleVersion: GradleVersion,
|
||||||
|
providedJdk: JdkVersions.ProvidedJdk,
|
||||||
|
androidVersion: String,
|
||||||
|
withRepositoryRoot: (Path) -> (Unit),
|
||||||
|
) {
|
||||||
|
project(
|
||||||
|
"multiplatformResources/publication",
|
||||||
|
gradleVersion,
|
||||||
|
buildJdk = providedJdk.location,
|
||||||
|
) {
|
||||||
|
buildWithAGPVersion(
|
||||||
|
":publishAllPublicationsToMavenRepository",
|
||||||
|
androidVersion,
|
||||||
|
defaultBuildOptions,
|
||||||
|
)
|
||||||
|
withRepositoryRoot(projectPath.resolve("build/repo"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+63
-43
@@ -5,16 +5,61 @@ import java.nio.file.Paths
|
|||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.util.capitalize
|
import org.jetbrains.kotlin.incremental.testingUtils.assertEqualDirectoriesIgnoringDotFiles
|
||||||
import org.jetbrains.kotlin.incremental.testingUtils.assertEqualDirectories
|
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
import kotlin.io.path.name
|
||||||
|
|
||||||
@MppGradlePluginTests
|
@MppGradlePluginTests
|
||||||
|
@AndroidTestVersions(minVersion = TestVersions.AGP.AGP_73)
|
||||||
@DisplayName("Test multiplatform resources publication")
|
@DisplayName("Test multiplatform resources publication")
|
||||||
class MultiplatformResourcesPublicationIT : KGPBaseTest() {
|
class MultiplatformResourcesPublicationIT : KGPBaseTest() {
|
||||||
|
|
||||||
|
@DisplayName("Multiplatform resources publication for Android target with release build type")
|
||||||
|
@GradleAndroidTest
|
||||||
|
fun testAndroidReleaseResourcesPublication(
|
||||||
|
gradleVersion: GradleVersion,
|
||||||
|
androidVersion: String,
|
||||||
|
providedJdk: JdkVersions.ProvidedJdk,
|
||||||
|
) {
|
||||||
|
project(
|
||||||
|
"multiplatformResources/publication",
|
||||||
|
gradleVersion,
|
||||||
|
buildJdk = providedJdk.location,
|
||||||
|
) {
|
||||||
|
buildWithAGPVersion(
|
||||||
|
":publishAndroidReleasePublicationToMavenRepository",
|
||||||
|
androidVersion,
|
||||||
|
defaultBuildOptions,
|
||||||
|
)
|
||||||
|
val publishedAarPath = "build/repo/test/publication-android/1.0/publication-android-1.0.aar"
|
||||||
|
val classesInAar = projectPath.resolve("classesInAar")
|
||||||
|
val classesJar = "classes.jar"
|
||||||
|
unzip(
|
||||||
|
projectPath.resolve(publishedAarPath),
|
||||||
|
classesInAar,
|
||||||
|
filesStartingWith = classesJar
|
||||||
|
)
|
||||||
|
compareEmbeddedResources(
|
||||||
|
inputZip = classesInAar.resolve(classesJar),
|
||||||
|
reference = reference("androidMain")
|
||||||
|
)
|
||||||
|
|
||||||
|
val assetsInAar = projectPath.resolve("assetsInAar")
|
||||||
|
unzip(
|
||||||
|
projectPath.resolve(publishedAarPath),
|
||||||
|
assetsInAar,
|
||||||
|
filesStartingWith = "assets"
|
||||||
|
)
|
||||||
|
assertEqualDirectoriesIgnoringDotFiles(
|
||||||
|
assetsInAar.toFile(),
|
||||||
|
reference("androidFonts").toFile(),
|
||||||
|
forgiveOtherExtraFiles = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@DisplayName("Multiplatform resources publication for jvm target")
|
@DisplayName("Multiplatform resources publication for jvm target")
|
||||||
@GradleAndroidTest
|
@GradleAndroidTest
|
||||||
fun testJvmResourcesPublication(
|
fun testJvmResourcesPublication(
|
||||||
@@ -28,7 +73,7 @@ class MultiplatformResourcesPublicationIT : KGPBaseTest() {
|
|||||||
providedJdk,
|
providedJdk,
|
||||||
publicationTask = ":publishJvmPublicationToMavenRepository",
|
publicationTask = ":publishJvmPublicationToMavenRepository",
|
||||||
publishedArchive = "build/repo/test/publication-jvm/1.0/publication-jvm-1.0.jar",
|
publishedArchive = "build/repo/test/publication-jvm/1.0/publication-jvm-1.0.jar",
|
||||||
reference = "jvm",
|
referenceName = "jvm",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +83,7 @@ class MultiplatformResourcesPublicationIT : KGPBaseTest() {
|
|||||||
providedJdk: JdkVersions.ProvidedJdk,
|
providedJdk: JdkVersions.ProvidedJdk,
|
||||||
publicationTask: String,
|
publicationTask: String,
|
||||||
publishedArchive: String,
|
publishedArchive: String,
|
||||||
reference: String,
|
referenceName: String,
|
||||||
) {
|
) {
|
||||||
project(
|
project(
|
||||||
"multiplatformResources/publication",
|
"multiplatformResources/publication",
|
||||||
@@ -48,61 +93,36 @@ class MultiplatformResourcesPublicationIT : KGPBaseTest() {
|
|||||||
buildWithAGPVersion(
|
buildWithAGPVersion(
|
||||||
publicationTask,
|
publicationTask,
|
||||||
androidVersion,
|
androidVersion,
|
||||||
|
defaultBuildOptions,
|
||||||
)
|
)
|
||||||
compareEmbeddedResources(
|
compareEmbeddedResources(
|
||||||
publishedArchive,
|
projectPath.resolve(publishedArchive),
|
||||||
reference
|
reference(referenceName)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestProject.buildWithAGPVersion(
|
private fun TestProject.reference(
|
||||||
task: String,
|
named: String
|
||||||
androidVersion: String,
|
): Path = projectPath.resolve("reference/$named")
|
||||||
) {
|
|
||||||
build(
|
|
||||||
task,
|
|
||||||
buildOptions = defaultBuildOptions.copy(androidVersion = androidVersion)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun TestProject.compareEmbeddedResources(
|
private fun TestProject.compareEmbeddedResources(
|
||||||
inputZip: String,
|
inputZip: Path,
|
||||||
reference: String,
|
reference: Path,
|
||||||
) {
|
) {
|
||||||
val publishedResources = projectPath.resolve("published/${reference}")
|
val publishedResources = projectPath.resolve("published/${reference.name}")
|
||||||
unzip(
|
unzip(
|
||||||
inputZip = inputZip,
|
inputZip = inputZip,
|
||||||
outputDir = publishedResources,
|
outputDir = publishedResources,
|
||||||
filesStartingWith = "embed",
|
filesStartingWith = "embed",
|
||||||
)
|
)
|
||||||
val referenceResources = projectPath.resolve("reference/$reference")
|
|
||||||
assertDirectoryExists(publishedResources)
|
assertDirectoryExists(publishedResources)
|
||||||
assertDirectoryExists(referenceResources)
|
assertDirectoryExists(reference)
|
||||||
assertEqualDirectories(
|
assertEqualDirectoriesIgnoringDotFiles(
|
||||||
publishedResources.toFile(),
|
publishedResources.toFile(),
|
||||||
referenceResources.toFile(),
|
reference.toFile(),
|
||||||
forgiveExtraFiles = false,
|
forgiveOtherExtraFiles = false,
|
||||||
filter = { !it.name.startsWith(".") }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestProject.unzip(
|
}
|
||||||
inputZip: String,
|
|
||||||
outputDir: Path,
|
|
||||||
filesStartingWith: String,
|
|
||||||
) {
|
|
||||||
ZipFile(projectPath.resolve(inputZip).toFile()).use {
|
|
||||||
it.entries().asSequence().filter { it.name.startsWith(filesStartingWith) && !it.isDirectory }.forEach { entry ->
|
|
||||||
val outputFile = outputDir.resolve(Paths.get(entry.name))
|
|
||||||
if (!outputFile.parent.toFile().exists())
|
|
||||||
Files.createDirectories(outputFile.parent)
|
|
||||||
|
|
||||||
it.getInputStream(entry).use { input ->
|
|
||||||
Files.copy(input, outputFile, StandardCopyOption.REPLACE_EXISTING)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2024 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.mpp.resources
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.BuildOptions
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.TestProject
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.build
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import java.nio.file.StandardCopyOption
|
||||||
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
|
fun TestProject.buildWithAGPVersion(
|
||||||
|
task: String,
|
||||||
|
androidVersion: String,
|
||||||
|
defaultBuildOptions: BuildOptions,
|
||||||
|
) {
|
||||||
|
build(
|
||||||
|
task,
|
||||||
|
buildOptions = defaultBuildOptions.copy(androidVersion = androidVersion)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unzip(
|
||||||
|
inputZip: Path,
|
||||||
|
outputDir: Path,
|
||||||
|
filesStartingWith: String,
|
||||||
|
) {
|
||||||
|
ZipFile(inputZip.toFile()).use {
|
||||||
|
it.entries().asSequence().filter { it.name.startsWith(filesStartingWith) && !it.isDirectory }.forEach { entry ->
|
||||||
|
val outputFile = outputDir.resolve(Paths.get(entry.name))
|
||||||
|
if (!outputFile.parent.toFile().exists())
|
||||||
|
Files.createDirectories(outputFile.parent)
|
||||||
|
|
||||||
|
it.getInputStream(entry).use { input ->
|
||||||
|
Files.copy(input, outputFile, StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform") apply false
|
||||||
|
id("com.android.application") apply false
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
@file:OptIn(ComposeKotlinGradlePluginApi::class)
|
||||||
|
|
||||||
|
import org.gradle.api.provider.Provider
|
||||||
|
import org.jetbrains.kotlin.gradle.ComposeKotlinGradlePluginApi
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.resources.KotlinTargetResourcesPublication
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
group = "test"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
id("com.android.application")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api(project(":projectDependency"))
|
||||||
|
api("test:publication:+")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val publication = project.ext.get(
|
||||||
|
KotlinTargetResourcesPublication.EXTENSION_NAME
|
||||||
|
) as KotlinTargetResourcesPublication
|
||||||
|
|
||||||
|
listOf(
|
||||||
|
androidTarget {
|
||||||
|
publishAllLibraryVariants()
|
||||||
|
compilations.all {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).forEach { target ->
|
||||||
|
val fontsFilter = if (target is KotlinAndroidTarget) listOf("fonts/*") else emptyList()
|
||||||
|
val relativeResourcePlacement = provider { File("embed/self") }
|
||||||
|
val sourceSetPathProvider: (KotlinSourceSet) -> (Provider<File>) = { sourceSet ->
|
||||||
|
project.provider { project.file("src/${sourceSet.name}/multiplatformResources") }
|
||||||
|
}
|
||||||
|
|
||||||
|
publication.publishResourcesAsKotlinComponent(
|
||||||
|
target = target,
|
||||||
|
resourcePathForSourceSet = { sourceSet ->
|
||||||
|
KotlinTargetResourcesPublication.ResourceRoot(
|
||||||
|
resourcesBaseDirectory = sourceSetPathProvider(sourceSet),
|
||||||
|
includes = emptyList(),
|
||||||
|
excludes = fontsFilter,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
relativeResourcePlacement = relativeResourcePlacement,
|
||||||
|
)
|
||||||
|
if (target is KotlinAndroidTarget) {
|
||||||
|
publication.publishInAndroidAssets(
|
||||||
|
target = target,
|
||||||
|
resourcePathForSourceSet = { sourceSet ->
|
||||||
|
KotlinTargetResourcesPublication.ResourceRoot(
|
||||||
|
resourcesBaseDirectory = sourceSetPathProvider(sourceSet),
|
||||||
|
includes = fontsFilter,
|
||||||
|
excludes = emptyList(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
relativeResourcePlacement = relativeResourcePlacement,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "test.consumer"
|
||||||
|
compileSdk = 34
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = 24
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="false"
|
||||||
|
android:supportsRtl="true">
|
||||||
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
package project
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fontsFromProject
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
selfResources
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
@file:OptIn(ComposeKotlinGradlePluginApi::class)
|
||||||
|
|
||||||
|
import org.gradle.api.provider.Provider
|
||||||
|
import org.jetbrains.kotlin.gradle.ComposeKotlinGradlePluginApi
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.resources.KotlinTargetResourcesPublication
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
group = "test"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
id("com.android.library")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
val publication = project.ext.get(
|
||||||
|
KotlinTargetResourcesPublication.EXTENSION_NAME
|
||||||
|
) as KotlinTargetResourcesPublication
|
||||||
|
|
||||||
|
listOf(
|
||||||
|
androidTarget {
|
||||||
|
publishAllLibraryVariants()
|
||||||
|
compilations.all {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
jvm(),
|
||||||
|
).forEach { target ->
|
||||||
|
val fontsFilter = if (target is KotlinAndroidTarget) listOf("fonts/*") else emptyList()
|
||||||
|
val relativeResourcePlacement = provider { File("embed/subproject") }
|
||||||
|
val sourceSetPathProvider: (KotlinSourceSet) -> (Provider<File>) = { sourceSet ->
|
||||||
|
project.provider { project.file("src/${sourceSet.name}/multiplatformResources") }
|
||||||
|
}
|
||||||
|
|
||||||
|
publication.publishResourcesAsKotlinComponent(
|
||||||
|
target = target,
|
||||||
|
resourcePathForSourceSet = { sourceSet ->
|
||||||
|
KotlinTargetResourcesPublication.ResourceRoot(
|
||||||
|
resourcesBaseDirectory = sourceSetPathProvider(sourceSet),
|
||||||
|
includes = emptyList(),
|
||||||
|
excludes = fontsFilter,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
relativeResourcePlacement = relativeResourcePlacement,
|
||||||
|
)
|
||||||
|
if (target is KotlinAndroidTarget) {
|
||||||
|
publication.publishInAndroidAssets(
|
||||||
|
target = target,
|
||||||
|
resourcePathForSourceSet = { sourceSet ->
|
||||||
|
KotlinTargetResourcesPublication.ResourceRoot(
|
||||||
|
resourcesBaseDirectory = sourceSetPathProvider(sourceSet),
|
||||||
|
includes = fontsFilter,
|
||||||
|
excludes = emptyList(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
relativeResourcePlacement = relativeResourcePlacement,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven("${buildDir}/repo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "test.projectDependency"
|
||||||
|
compileSdk = 34
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = 24
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
package project
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
selfFont
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fromProject
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
font
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fontsFromProject
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
selfFont
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
innerInCommon
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
androidMain
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
onlyInAndroidMain
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
selfResources
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fromProject
|
||||||
+49
-5
@@ -1,35 +1,71 @@
|
|||||||
@file:OptIn(ComposeKotlinGradlePluginApi::class)
|
@file:OptIn(ComposeKotlinGradlePluginApi::class)
|
||||||
|
|
||||||
|
import org.gradle.api.provider.Provider
|
||||||
import org.jetbrains.kotlin.gradle.ComposeKotlinGradlePluginApi
|
import org.jetbrains.kotlin.gradle.ComposeKotlinGradlePluginApi
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.resources.KotlinTargetResourcesPublication
|
import org.jetbrains.kotlin.gradle.plugin.mpp.resources.KotlinTargetResourcesPublication
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
group = "test"
|
group = "test"
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform")
|
kotlin("multiplatform")
|
||||||
|
id("com.android.library")
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
val publication = project.ext.get(
|
val publication = project.ext.get(
|
||||||
KotlinTargetResourcesPublication.EXTENSION_NAME
|
KotlinTargetResourcesPublication.EXTENSION_NAME
|
||||||
) as KotlinTargetResourcesPublication
|
) as KotlinTargetResourcesPublication
|
||||||
|
|
||||||
listOf(
|
listOf(
|
||||||
|
androidTarget {
|
||||||
|
publishAllLibraryVariants()
|
||||||
|
compilations.all {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
jvm(),
|
jvm(),
|
||||||
).forEach { target ->
|
).forEach { target ->
|
||||||
|
val fontsFilter = if (target is KotlinAndroidTarget) listOf("fonts/*") else emptyList()
|
||||||
|
val relativeResourcePlacement = provider { File("embed/published") }
|
||||||
|
val sourceSetPathProvider: (KotlinSourceSet) -> (Provider<File>) = { sourceSet ->
|
||||||
|
project.provider { project.file("src/${sourceSet.name}/multiplatformResources") }
|
||||||
|
}
|
||||||
|
|
||||||
publication.publishResourcesAsKotlinComponent(
|
publication.publishResourcesAsKotlinComponent(
|
||||||
target,
|
target = target,
|
||||||
{ sourceSet ->
|
resourcePathForSourceSet = { sourceSet ->
|
||||||
KotlinTargetResourcesPublication.ResourceRoot(
|
KotlinTargetResourcesPublication.ResourceRoot(
|
||||||
resourcesBaseDirectory = project.provider { project.file("src/${sourceSet.name}/multiplatformResources") },
|
resourcesBaseDirectory = sourceSetPathProvider(sourceSet),
|
||||||
includes = emptyList(),
|
includes = emptyList(),
|
||||||
excludes = emptyList()
|
excludes = fontsFilter,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
provider { File("embed/inside") }
|
relativeResourcePlacement = relativeResourcePlacement,
|
||||||
)
|
)
|
||||||
|
if (target is KotlinAndroidTarget) {
|
||||||
|
publication.publishInAndroidAssets(
|
||||||
|
target = target,
|
||||||
|
resourcePathForSourceSet = { sourceSet ->
|
||||||
|
KotlinTargetResourcesPublication.ResourceRoot(
|
||||||
|
resourcesBaseDirectory = sourceSetPathProvider(sourceSet),
|
||||||
|
includes = fontsFilter,
|
||||||
|
excludes = emptyList(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
relativeResourcePlacement = relativeResourcePlacement,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,3 +74,11 @@ publishing {
|
|||||||
maven("${buildDir}/repo")
|
maven("${buildDir}/repo")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace = "test.publication"
|
||||||
|
compileSdk = 34
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = 24
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
font
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
inCommon
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
innerInCommon
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
androidMain
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
onlyInAndroidMain
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
inCommon
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
innerInCommon
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
font
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
androidMain
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
onlyInAndroidMain
|
||||||
Reference in New Issue
Block a user