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