[Gradle, JS] Extract archiveType property on Configurator level
This commit is contained in:
+16
-14
@@ -341,6 +341,8 @@ abstract class KotlinOnlyTargetConfigurator<KotlinCompilationType : KotlinCompil
|
||||
createDefaultSourceSets,
|
||||
createTestCompilation
|
||||
) {
|
||||
open val archiveType: String = ArtifactTypeDefinition.JAR_TYPE
|
||||
|
||||
internal abstract fun buildCompilationProcessor(compilation: KotlinCompilationType): KotlinCompilationProcessor<*>
|
||||
|
||||
override fun configureCompilations(target: KotlinTargetType) {
|
||||
@@ -355,13 +357,13 @@ abstract class KotlinOnlyTargetConfigurator<KotlinCompilationType : KotlinCompil
|
||||
}
|
||||
|
||||
/** The implementations are expected to create a [Zip] task under the name [KotlinTarget.artifactsTaskName] of the [target]. */
|
||||
protected open fun createJarTasks(target: KotlinTargetType): Pair<String, Zip> {
|
||||
val result = target.project.tasks.create(target.artifactsTaskName, Jar::class.java)
|
||||
result.description = "Assembles a jar archive containing the main classes."
|
||||
result.group = BasePlugin.BUILD_GROUP
|
||||
result.from(target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME).output.allOutputs)
|
||||
|
||||
return ArtifactTypeDefinition.JAR_TYPE to result
|
||||
protected open fun createArchiveTasks(target: KotlinTargetType): Zip {
|
||||
//TODO Change Jar on Zip
|
||||
return target.project.tasks.create(target.artifactsTaskName, Jar::class.java).apply {
|
||||
description = "Assembles an archive containing the main classes."
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
from(target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME).output.allOutputs)
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureArchivesAndComponent(target: KotlinTargetType) {
|
||||
@@ -369,7 +371,7 @@ abstract class KotlinOnlyTargetConfigurator<KotlinCompilationType : KotlinCompil
|
||||
|
||||
val mainCompilation = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
|
||||
val (type, task) = createJarTasks(target)
|
||||
val task = createArchiveTasks(target)
|
||||
|
||||
target.disambiguationClassifier?.let { task.appendix = it.toLowerCase() }
|
||||
|
||||
@@ -378,28 +380,28 @@ abstract class KotlinOnlyTargetConfigurator<KotlinCompilationType : KotlinCompil
|
||||
project.afterEvaluate {
|
||||
project.artifacts.add(Dependency.ARCHIVES_CONFIGURATION, task) { jarArtifact ->
|
||||
jarArtifact.builtBy(task)
|
||||
jarArtifact.type = type
|
||||
jarArtifact.type = archiveType
|
||||
|
||||
val apiElementsConfiguration = project.configurations.getByName(target.apiElementsConfigurationName)
|
||||
addJar(apiElementsConfiguration, jarArtifact, type)
|
||||
addJar(apiElementsConfiguration, jarArtifact)
|
||||
|
||||
if (mainCompilation is KotlinCompilationToRunnableFiles<*>) {
|
||||
val runtimeConfiguration = project.configurations.getByName(mainCompilation.deprecatedRuntimeConfigurationName)
|
||||
val runtimeElementsConfiguration = project.configurations.getByName(target.runtimeElementsConfigurationName)
|
||||
addJar(runtimeConfiguration, jarArtifact, type)
|
||||
addJar(runtimeElementsConfiguration, jarArtifact, type)
|
||||
addJar(runtimeConfiguration, jarArtifact)
|
||||
addJar(runtimeElementsConfiguration, jarArtifact)
|
||||
// TODO Check Gradle's special split into variants for classes & resources -- do we need that too?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addJar(configuration: Configuration, jarArtifact: PublishArtifact, type: String) {
|
||||
private fun addJar(configuration: Configuration, jarArtifact: PublishArtifact) {
|
||||
val publications = configuration.outgoing
|
||||
|
||||
// Configure an implicit variant
|
||||
publications.artifacts.add(jarArtifact)
|
||||
publications.attributes.attribute(ArtifactAttributes.ARTIFACT_FORMAT, type)
|
||||
publications.attributes.attribute(ArtifactAttributes.ARTIFACT_FORMAT, archiveType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -22,6 +22,9 @@ open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
||||
|
||||
override val testRunClass: Class<KotlinJsReportAggregatingTestRun> get() = KotlinJsReportAggregatingTestRun::class.java
|
||||
|
||||
override val archiveType: String
|
||||
get() = KLIB_TYPE
|
||||
|
||||
override fun createTestRun(
|
||||
name: String,
|
||||
target: KotlinJsIrTarget
|
||||
@@ -50,12 +53,11 @@ open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
||||
return KotlinJsIrSourceSetProcessor(tasksProvider, compilation, kotlinPluginVersion)
|
||||
}
|
||||
|
||||
override fun createJarTasks(target: KotlinJsIrTarget): Pair<String, Zip> {
|
||||
val (_, task) = super.createJarTasks(target)
|
||||
// not archiveExtension because it is since Gradle 5.1 only
|
||||
task.extension = KLIB_TYPE
|
||||
|
||||
return KLIB_TYPE to task
|
||||
override fun createArchiveTasks(target: KotlinJsIrTarget): Zip {
|
||||
return super.createArchiveTasks(target).apply {
|
||||
// not archiveExtension because it is since Gradle 5.1 only
|
||||
extension = KLIB_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureCompilations(target: KotlinJsIrTarget) {
|
||||
|
||||
+2
-2
@@ -132,8 +132,8 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||
override fun run() = Unit
|
||||
}
|
||||
|
||||
override fun createJarTasks(target: KotlinMetadataTarget): Pair<String, Zip> {
|
||||
val result = super.createJarTasks(target)
|
||||
override fun createArchiveTasks(target: KotlinMetadataTarget): Zip {
|
||||
val result = super.createArchiveTasks(target)
|
||||
|
||||
if (target.project.isKotlinGranularMetadataEnabled) {
|
||||
target.project.locateTask<Jar>(target.artifactsTaskName)!!.configure {
|
||||
|
||||
Reference in New Issue
Block a user