import groovy.io.FileType
import org.jetbrains.CrossPlatformExec
import shadow.org.apache.commons.io.FileUtils
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.nio.file.attribute.BasicFileAttributes
apply plugin: 'kotlin'
apply plugin: 'com.github.johnrengelman.shadow'
dependencies {
shadow project(":runners:fatjar")
shadow "org.apache.maven:maven-core:$maven_version"
shadow "org.apache.maven:maven-model:$maven_version"
shadow "org.apache.maven:maven-plugin-api:$maven_version"
shadow "org.apache.maven:maven-archiver:$maven_archiver_version"
shadow "org.codehaus.plexus:plexus-utils:$plexus_utils_version"
shadow "org.codehaus.plexus:plexus-archiver:$plexus_archiver_version"
shadow "org.apache.maven.plugin-tools:maven-plugin-annotations:$maven_plugin_tools_version"
}
task generatePom() {
inputs.file(new File(projectDir, "pom.tpl.xml"))
outputs.file(new File(buildDir, "pom.xml"))
doLast {
final pomTemplate = new File(projectDir, "pom.tpl.xml")
final pom = new File(buildDir, "pom.xml")
pom.text = pomTemplate.text.replace("dokka_version", "$dokka_version")
.replace("", "$maven_version")
.replace("maven-plugin-plugin", "$maven_plugin_tools_version")
}
}
task mergeClassOutputs doLast {
def sourceDir = new File(buildDir, "classes/kotlin")
def targetDir = new File(buildDir, "classes/java")
sourceDir.eachFileRecurse FileType.ANY, {
def filePath = it.toPath()
def targetFilePath = targetDir.toPath().resolve(sourceDir.toPath().relativize(filePath))
if (it.isFile()) {
Files.move(filePath, targetFilePath, StandardCopyOption.REPLACE_EXISTING)
} else if (it.isDirectory()) {
targetFilePath.toFile().mkdirs()
}
}
}
task pluginDescriptor(type: CrossPlatformExec) {
workingDir buildDir
commandLine mvn, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:descriptor'
dependsOn mergeClassOutputs
}
task helpMojo(type: CrossPlatformExec) {
workingDir buildDir
commandLine mvn, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:helpmojo'
dependsOn mergeClassOutputs
}
helpMojo.dependsOn generatePom
sourceSets.main.java.srcDir("$buildDir/generated-sources/plugin")
compileJava.dependsOn helpMojo
pluginDescriptor.dependsOn generatePom
shadowJar {
baseName = 'dokka-maven-plugin'
classifier = ''
}
shadowJar.dependsOn pluginDescriptor
task sourceJar(type: Jar) {
from sourceSets.main.allSource
}
apply plugin: 'maven-publish'
publishing {
publications {
dokkaMavenPlugin(MavenPublication) { publication ->
artifactId = 'dokka-maven-plugin'
artifact sourceJar {
classifier "sources"
}
project.shadow.component(publication)
pom.withXml {
Node root = asNode()
def dependency = new XmlParser().parseText('''
com.sun
tools
1.8.0
system
${toolsjar}
''')
root.children().find {
return it.name() == "dependencies"
}.append(dependency)
def profiles = new XmlParser().parseText('''
default-profile
true
${java.home}/../lib/tools.jar
${java.home}/../lib/tools.jar
mac-profile
false
${java.home}/../Classes/classes.jar
${java.home}/../Classes/classes.jar
''')
root.append(profiles)
}
}
}
}
bintrayPublication(project, ['dokkaMavenPlugin'])