All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.astrainteractive.gradleplugin.JvmSourceTargetPlugin.kt Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
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"])
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy