Improve BuildMiraiPluginTask

This commit is contained in:
Him188 2021-03-27 19:27:30 +08:00
parent 4308c59da2
commit 8b7dc78a5d
2 changed files with 23 additions and 11 deletions

View File

@ -1,24 +1,37 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.console.gradle package net.mamoe.mirai.console.gradle
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputFile
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import java.io.File import java.io.File
@CacheableTask @CacheableTask
public open class BuildMiraiPluginTask : ShadowJar() { public open class BuildMiraiPluginTask(
@Internal @field:Internal
public var targetField: KotlinTarget? = null internal val target: KotlinTarget
) : ShadowJar() {
@get:Internal
public val target: KotlinTarget
get() = targetField!!
/** /**
* ShadowJar 打包结果 * ShadowJar 打包结果
*/ */
@get:Internal @get:OutputFile
public val output: File public val output: File
get() = outputs.files.singleFile get() = outputs.files.singleFile
public companion object {
/**
* Kotlin 单平台或 Java 时的默认 task .
*/
public const val DEFAULT_NAME: String = "buildPlugin"
}
} }

View File

@ -102,9 +102,8 @@ public class MiraiConsoleGradlePlugin : Plugin<Project> {
tasks.findByName("shadowJar")?.enabled = false tasks.findByName("shadowJar")?.enabled = false
fun registerBuildPluginTask(target: KotlinTarget, isSingleTarget: Boolean) { fun registerBuildPluginTask(target: KotlinTarget, isSingleTarget: Boolean) {
tasks.create("buildPlugin".wrapNameWithPlatform(target, isSingleTarget), BuildMiraiPluginTask::class.java).apply shadow@{ tasks.create("buildPlugin".wrapNameWithPlatform(target, isSingleTarget), BuildMiraiPluginTask::class.java, target).apply shadow@{
group = "mirai" group = "mirai"
targetField = target
archiveExtension.set("mirai.jar") archiveExtension.set("mirai.jar")