aboutsummaryrefslogtreecommitdiff
path: root/runners/maven-plugin/build.gradle.kts
blob: 6cd0395ee36f822ed839411c3fcf8348ff3ea401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import org.jetbrains.CrossPlatformExec
import org.jetbrains.SetupMaven
import org.jetbrains.registerDokkaArtifactPublication

plugins {
    org.jetbrains.conventions.`kotlin-jvm`
    org.jetbrains.conventions.`maven-publish`
}

val setupMaven by tasks.register<SetupMaven>("setupMaven")

dependencies {
    implementation(project(":core"))
    implementation("org.apache.maven:maven-core:${setupMaven.mavenVersion}")
    implementation("org.apache.maven:maven-plugin-api:${setupMaven.mavenVersion}")
    implementation("org.apache.maven.plugin-tools:maven-plugin-annotations:${setupMaven.mavenPluginToolsVersion}")
    implementation("org.apache.maven:maven-archiver:2.5")
    implementation(kotlin("stdlib-jdk8"))
}

val mavenBuildDir = setupMaven.mavenBuildDir
val mavenBinDir = setupMaven.mavenBinDir

tasks.clean {
    delete(mavenBuildDir)
    delete(mavenBinDir)
}

val generatePom by tasks.registering(Copy::class) {
    description = "Generate pom.xml for Maven Plugin Plugin"

    val dokka_version: String by project
    inputs.property("dokka_version", dokka_version)

    from("$projectDir/pom.tpl.xml") {
        rename("(.*).tpl.xml", "$1.xml")
    }
    into(setupMaven.mavenBuildDir)

    eachFile {
        filter { line ->
            line.replace("<maven.version></maven.version>", "<maven.version>${setupMaven.mavenVersion}</maven.version>")
        }
        filter { line ->
            line.replace("<version>dokka_version</version>", "<version>$dokka_version</version>")
        }
        filter { line ->
            line.replace(
                "<version>maven-plugin-plugin</version>",
                "<version>${setupMaven.mavenPluginToolsVersion}</version>"
            )
        }
    }
}

val syncClasses by tasks.registering(Sync::class) {
    description = "Copy compiled classes to the Maven build dir, for Maven Plugin task execution"

    dependsOn(tasks.compileKotlin, tasks.compileJava)
    from("$buildDir/classes/kotlin", "$buildDir/classes/java")
    into("${setupMaven.mavenBuildDir}/classes/java")

    preserve {
        include("**/*.class")
    }
}

val helpMojo by tasks.registering(CrossPlatformExec::class) {
    dependsOn(setupMaven, generatePom, syncClasses)
    workingDir(setupMaven.mavenBuildDir)
    commandLine(setupMaven.mvn, "-e", "-B", "org.apache.maven.plugins:maven-plugin-plugin:helpmojo")

    outputs.dir(layout.buildDirectory.dir("maven"))
}

val pluginDescriptor by tasks.registering(CrossPlatformExec::class) {
    dependsOn(setupMaven, generatePom, syncClasses)
    workingDir(setupMaven.mavenBuildDir)
    commandLine(setupMaven.mvn, "-e", "-B", "org.apache.maven.plugins:maven-plugin-plugin:descriptor")

    outputs.dir(layout.buildDirectory.dir("maven/classes/java/main/META-INF/maven"))
}

tasks.jar {
    dependsOn(pluginDescriptor, helpMojo)
    metaInf {
        from("${setupMaven.mavenBuildDir}/classes/java/main/META-INF")
    }
    manifest {
        attributes("Class-Path" to configurations.runtimeClasspath.map { configuration ->
            configuration.resolve().joinToString(" ") { it.name }
        })
    }
    duplicatesStrategy = DuplicatesStrategy.WARN
}


registerDokkaArtifactPublication("dokkaMavenPlugin") {
    artifactId = "dokka-maven-plugin"
}