aboutsummaryrefslogtreecommitdiff
path: root/build-logic/src/main/kotlin
diff options
context:
space:
mode:
authoraSemy <897017+aSemy@users.noreply.github.com>2023-03-16 02:15:49 +0100
committerGitHub <noreply@github.com>2023-03-16 02:15:49 +0100
commit12e2a3c6b8bf1533148ddf29c77e73f5045754a6 (patch)
treef6072f01aa8e43da84fa65d79d87d720ff7220c7 /build-logic/src/main/kotlin
parent34c0f73afa9c950b0eaf7fc3fbffb8dd600ba35a (diff)
downloaddokka-12e2a3c6b8bf1533148ddf29c77e73f5045754a6.tar.gz
dokka-12e2a3c6b8bf1533148ddf29c77e73f5045754a6.tar.bz2
dokka-12e2a3c6b8bf1533148ddf29c77e73f5045754a6.zip
Refactor Maven Runner build config (#2911)
Diffstat (limited to 'build-logic/src/main/kotlin')
-rw-r--r--build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts103
1 files changed, 103 insertions, 0 deletions
diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts
new file mode 100644
index 00000000..ec59da7b
--- /dev/null
+++ b/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts
@@ -0,0 +1,103 @@
+package org.jetbrains.conventions
+
+import org.gradle.kotlin.dsl.support.serviceOf
+
+/**
+ * Utility for downloading and installing a Maven binary.
+ *
+ * Provides the `setupMavenProperties` extension that contains the default versions and locations
+ * of the Maven binary.
+ *
+ * The task [installMavenBinary] will download and unzip the Maven bianry.
+ */
+
+plugins {
+ base
+}
+
+abstract class SetupMavenProperties {
+ abstract val mavenVersion: Property<String>
+ abstract val mavenPluginToolsVersion: Property<String>
+ abstract val mavenBuildDir: DirectoryProperty
+
+ /** Directory that will contain the unpacked Apache Maven dependency */
+ abstract val mavenInstallDir: DirectoryProperty
+
+ /**
+ * Path to the Maven executable.
+ *
+ * This should be different per OS:
+ *
+ * * Windows: `$mavenInstallDir/bin/mvn.cmd`
+ * * Unix: `$mavenInstallDir/bin/mvn`
+ */
+ abstract val mvn: RegularFileProperty
+}
+
+val setupMavenProperties =
+ extensions.create("setupMavenProperties", SetupMavenProperties::class).apply {
+ mavenVersion.convention(providers.gradleProperty("mavenVersion"))
+ mavenPluginToolsVersion.convention(providers.gradleProperty("mavenPluginToolsVersion"))
+
+ mavenBuildDir.convention(layout.buildDirectory.dir("maven"))
+ mavenInstallDir.convention(layout.buildDirectory.dir("apache-maven"))
+
+ val isWindowsProvider =
+ providers.systemProperty("os.name").map { "win" in it.toLowerCase() }
+
+ mvn.convention(
+ providers.zip(mavenInstallDir, isWindowsProvider) { mavenInstallDir, isWindows ->
+ mavenInstallDir.file(
+ when {
+ isWindows -> "bin/mvn.cmd"
+ else -> "bin/mvn"
+ }
+ )
+ }
+ )
+ }
+
+val mavenBinary by configurations.registering {
+ description = "used to download the Maven binary"
+ isCanBeResolved = true
+ isCanBeConsumed = false
+ isVisible = false
+
+ defaultDependencies {
+ addLater(setupMavenProperties.mavenVersion.map { mavenVersion ->
+ project.dependencies.create(
+ group = "org.apache.maven",
+ name = "apache-maven",
+ version = mavenVersion,
+ classifier = "bin",
+ ext = "zip"
+ )
+ })
+ }
+}
+
+tasks.clean {
+ delete(setupMavenProperties.mavenBuildDir)
+ delete(setupMavenProperties.mavenInstallDir)
+}
+
+val installMavenBinary by tasks.registering(Sync::class) {
+ val archives = serviceOf<ArchiveOperations>()
+ from(
+ mavenBinary.flatMap { conf ->
+ @Suppress("UnstableApiUsage")
+ val resolvedArtifacts = conf.incoming.artifacts.resolvedArtifacts
+
+ resolvedArtifacts.map { artifacts ->
+ artifacts.map { archives.zipTree(it.file) }
+ }
+ }
+ ) {
+ eachFile {
+ // drop the first directory inside the zipped Maven bin (apache-maven-$version)
+ relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray())
+ }
+ includeEmptyDirs = false
+ }
+ into(setupMavenProperties.mavenInstallDir)
+}