ru.astrainteractive.gradleplugin.JvmSourceTargetPlugin.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of convention Show documentation
Show all versions of convention Show documentation
GradlePlugin for my kotlin projects
package ru.astrainteractive.gradleplugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireJinfo
class JvmSourceTargetPlugin : Plugin {
override fun apply(target: Project) {
val jinfo = target.requireJinfo
target.configure {
kotlin.runCatching {
withSourcesJar()
withJavadocJar()
}
sourceCompatibility = jinfo.jsource
targetCompatibility = jinfo.jtarget
}
target.afterEvaluate {
target.tasks.withType {
options.encoding = "UTF-8"
}
}
target.tasks
.withType()
.configureEach {
kotlinOptions.jvmTarget = jinfo.ktarget.majorVersion
}
target.plugins.withId("org.gradle.maven-publish") {
target.configure {
publications.register("mavenJava", MavenPublication::class) {
from(target.components["java"])
}
}
}
}
}