Skip to content

Commit 5cea544

Browse files
committed
Fix the build system to properly create the android variant.
1 parent f7e3b5f commit 5cea544

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

core/compat/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ config {
9898

9999
afterEvaluate {
100100
dependencies {
101-
"android"(projects.coreAndroid)
101+
"androidRuntime"(projects.coreAndroid)
102102
}
103103
}
104104

project-plugins/src/main/kotlin/io/github/xmlutil/plugin/ProjectPlugin.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import org.gradle.api.JavaVersion
2828
import org.gradle.api.Plugin
2929
import org.gradle.api.Project
3030
import org.gradle.api.artifacts.VersionCatalogsExtension
31+
import org.gradle.api.attributes.Category
32+
import org.gradle.api.attributes.Usage
3133
import org.gradle.api.attributes.java.TargetJvmEnvironment
3234
import org.gradle.api.component.SoftwareComponentFactory
3335
import org.gradle.api.plugins.JavaPlugin
@@ -89,25 +91,37 @@ class ProjectPlugin @Inject constructor(
8991
}
9092

9193
if (e.createAndroidCompatComponent.get()) {
94+
val configurations = project.configurations
95+
9296
project.logger.warn("Creating compatible component")
93-
val component = softwareComponentFactory.adhoc("depOnlyComponent")
94-
project.components.add(component)
95-
val pseudoConfig = project.configurations.dependencyScope("android") {
97+
98+
val androidRuntime = configurations.dependencyScope("androidRuntime") {
99+
dependencies.add(project.dependencyFactory.create("io.github.pdvrieze.xmlutil:${project.name}:${project.version}"))
100+
}
101+
val androidRuntimeElements = configurations.consumable("androidRuntimeElements") {
102+
extendsFrom(androidRuntime.get())
96103
attributes {
104+
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_API))
105+
// see whether this should be library
106+
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
97107
attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, project.envAndroid)
98108
attribute(KotlinPlatformType.attribute, KotlinPlatformType.androidJvm)
99109
}
110+
}
100111

101-
component.addVariantsFromConfiguration(this) {
102-
mapToMavenScope("compile")
103-
}
104-
dependencies.add(project.dependencyFactory.create("io.github.pdvrieze.xmlutil:${project.name}:${project.version}"))
112+
val component = softwareComponentFactory.adhoc("androidComponent")
113+
project.components.add(component)
114+
115+
component.addVariantsFromConfiguration(androidRuntimeElements.get()) {
116+
logger.lifecycle("Add variant to runtime scope")
117+
mapToMavenScope("runtime")
105118
}
106119

120+
107121
project.extensions.configure<PublishingExtension> {
108122
publications {
109123
create<MavenPublication>("android") {
110-
artifactId = project.name
124+
artifactId = "${project.name}-android"
111125
from(component)
112126
}
113127
}

0 commit comments

Comments
 (0)