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
|
import org.gradle.kotlin.dsl.support.appendReproducibleNewLine
import org.jetbrains.registerDokkaArtifactPublication
plugins {
id("org.jetbrains.conventions.kotlin-jvm")
id("org.jetbrains.conventions.maven-publish")
id("org.jetbrains.conventions.maven-cli-setup")
}
dependencies {
implementation(projects.core)
implementation(libs.apache.mavenCore)
implementation(libs.apache.mavenPluginApi)
implementation(libs.apache.mavenPluginAnnotations)
implementation(libs.apache.mavenArchiver)
}
val mavenPluginTaskGroup = "maven plugin"
val generatePom by tasks.registering(Sync::class) {
description = "Generate pom.xml for Maven Plugin Plugin"
group = mavenPluginTaskGroup
val dokka_version: String by project
inputs.property("dokka_version", dokka_version)
val pomTemplateFile = layout.projectDirectory.file("pom.template.xml")
val mavenVersion = mavenCliSetup.mavenVersion.orNull
val mavenPluginToolsVersion = mavenCliSetup.mavenPluginToolsVersion.orNull
from(pomTemplateFile) {
rename { it.replace(".template.xml", ".xml") }
expand(
"mavenVersion" to mavenVersion,
"dokka_version" to dokka_version,
"mavenPluginToolsVersion" to mavenPluginToolsVersion,
)
}
into(temporaryDir)
}
val prepareMavenPluginBuildDir by tasks.registering(Sync::class) {
description = "Prepares all files for Maven Plugin task execution"
group = mavenPluginTaskGroup
from(tasks.compileKotlin.flatMap { it.destinationDirectory }) { into("classes/java/main") }
from(tasks.compileJava.flatMap { it.destinationDirectory }) { into("classes/java/main") }
from(generatePom)
into(mavenCliSetup.mavenBuildDir)
}
val helpMojo by tasks.registering(Exec::class) {
group = mavenPluginTaskGroup
dependsOn(tasks.installMavenBinary, prepareMavenPluginBuildDir)
workingDir(mavenCliSetup.mavenBuildDir)
executable(mavenCliSetup.mvn.get())
args("-e", "-B", "org.apache.maven.plugins:maven-plugin-plugin:helpmojo")
outputs.dir(mavenCliSetup.mavenBuildDir)
doLast("normalize maven-plugin-help.properties") {
// The maven-plugin-help.properties file contains a timestamp by default.
// It should be removed as it is not reproducible and impacts Gradle caching
val pluginHelpProperties = workingDir.resolve("maven-plugin-help.properties")
pluginHelpProperties.writeText(
buildString {
val lines = pluginHelpProperties.readText().lines().iterator()
// the first line is a descriptive comment
appendReproducibleNewLine(lines.next())
// the second line is the timestamp, which should be ignored
lines.next()
// the remaining lines are properties
lines.forEach { appendReproducibleNewLine(it) }
}
)
}
}
val pluginDescriptor by tasks.registering(Exec::class) {
group = mavenPluginTaskGroup
dependsOn(tasks.installMavenBinary, prepareMavenPluginBuildDir)
workingDir(mavenCliSetup.mavenBuildDir)
executable(mavenCliSetup.mvn.get())
args(
"-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(mavenCliSetup.mavenBuildDir.map { it.dir("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"
}
|