diff options
Diffstat (limited to 'runners/maven-plugin/build.gradle.kts')
-rw-r--r-- | runners/maven-plugin/build.gradle.kts | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/runners/maven-plugin/build.gradle.kts b/runners/maven-plugin/build.gradle.kts new file mode 100644 index 00000000..2dffd71c --- /dev/null +++ b/runners/maven-plugin/build.gradle.kts @@ -0,0 +1,115 @@ +import org.jetbrains.configureBintrayPublication + +/** + * [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 maven_version: String by project + +dependencies { + implementation(project(":core")) + implementation("org.apache.maven:maven-core:$maven_version") + implementation("org.apache.maven:maven-plugin-api:$maven_version") + val maven_plugin_tools_version: String by project + implementation("org.apache.maven.plugin-tools:maven-plugin-annotations:$maven_plugin_tools_version") + val maven_archiver_version: String by project + implementation("org.apache.maven:maven-archiver:$maven_archiver_version") + + mavenBin(group = "org.apache.maven", name = "apache-maven", version = maven_version, classifier = "bin", ext = "zip") + compileOnly(kotlin("stdlib-jdk8")) +} + +val mavenBinDir = "$buildDir/maven-bin" +val mavenBuildDir = "$buildDir/maven" +val mvn = File(mavenBinDir, "apache-maven-$maven_version/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 + val maven_plugin_tools_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>$maven_version</maven.version>") + } + filter { line -> + line.replace("<version>dokka_version</version>", "<version>$dokka_version</version>") + } + filter { line -> + line.replace("<version>maven-plugin-plugin</version>", "<version>$maven_plugin_tools_version</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(org.jetbrains.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(org.jetbrains.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") |