aboutsummaryrefslogtreecommitdiff
path: root/runners/maven-plugin/build.gradle.kts
blob: d9fc4f6f1ea351f577b4f70d309d25275936cec6 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import org.jetbrains.configureBintrayPublication
import org.jetbrains.CrossPlatformExec
/**
 * [mavenBin] configuration is used to download Maven Plugin Plugin
 * for generating plugin-help.xml and plugin.xml files
 */
val mavenBin: Configuration by configurations.creating

val mavenVersion = "3.5.0"
val mavenPluginToolsVersion = "3.5.2"
val aetherVersion = "1.1.0"

dependencies {
    implementation(project(":core"))
    implementation("org.apache.maven:maven-core:$mavenVersion")
    implementation("org.apache.maven:maven-plugin-api:$mavenVersion")
    implementation("org.apache.maven.plugin-tools:maven-plugin-annotations:$mavenPluginToolsVersion")
    implementation("org.apache.maven:maven-archiver:2.5")
    implementation(kotlin("stdlib-jdk8"))
    implementation("org.eclipse.aether:aether-api:${aetherVersion}")
    implementation("org.eclipse.aether:aether-spi:${aetherVersion}")
    implementation("org.eclipse.aether:aether-impl:${aetherVersion}")
    implementation("org.eclipse.aether:aether-connector-basic:${aetherVersion}")
    implementation("org.eclipse.aether:aether-transport-file:${aetherVersion}")
    implementation("org.eclipse.aether:aether-transport-http:${aetherVersion}")
    implementation("org.apache.maven:maven-aether-provider:3.3.3")
    mavenBin(group = "org.apache.maven", name = "apache-maven", version = mavenVersion, classifier = "bin", ext = "zip")
}

val mavenBinDir = "$buildDir/maven-bin"
val mavenBuildDir = "$buildDir/maven"
val mvn = File(mavenBinDir, "apache-maven-$mavenVersion/bin/mvn")

tasks.named<Delete>("clean") {
    delete(mavenBinDir)
}

/**
 * Copy Maven Plugin Plugin to [mavenBinDir] directory
 */
val setupMaven by tasks.registering(Sync::class) {
    from(mavenBin.map { zipTree(it) })
    into(mavenBinDir)
}

/**
 * Generate pom.xml for Maven Plugin Plugin
 */
val generatePom by tasks.registering(Copy::class) {
    val dokka_version: String by project

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

    eachFile {
        filter { line ->
            line.replace("<maven.version></maven.version>", "<maven.version>$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>$mavenPluginToolsVersion</version>")
        }
    }
}

/**
 * Copy compiled classes to [mavenBuildDir] for Maven Plugin Plugin
 */
val syncClasses by tasks.registering(Sync::class) {
    dependsOn(tasks.compileKotlin, tasks.compileJava)
    from("$buildDir/classes/kotlin", "$buildDir/classes/java")
    into("$mavenBuildDir/classes/java")

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

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

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

val sourceJar by tasks.registering(Jar::class) {
    archiveClassifier.set("sources")
    from(sourceSets["main"].allSource)
}

tasks.named<Jar>("jar") {
    dependsOn(pluginDescriptor, helpMojo)
    metaInf {
        from("$mavenBuildDir/classes/java/main/META-INF")
    }
    manifest {
        attributes("Class-Path" to configurations.runtimeClasspath.get().files.joinToString(" ") { it.name })
    }
}

publishing {
    publications {
        register<MavenPublication>("dokkaMavenPlugin") {
            artifactId = "dokka-maven-plugin"
            from(components["java"])
            artifact(sourceJar.get())
        }
    }
}

configureBintrayPublication("dokkaMavenPlugin")