Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Maven Runner build config (#2911)
- Loading branch information
Showing
5 changed files
with
182 additions
and
60 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters