[Gradle, JS] Fix node.js repository declaration

^KT-47557 fixed
This commit is contained in:
Ilya Goncharov
2021-07-01 10:34:52 +03:00
committed by Space
parent f05110f99b
commit e0c1f50f03
3 changed files with 27 additions and 25 deletions
@@ -11,7 +11,8 @@ data class NodeJsEnv(
val platformName: String, val platformName: String,
val architectureName: String, val architectureName: String,
val ivyDependency: String val ivyDependency: String,
val downloadBaseUrl: String
) { ) {
val isWindows: Boolean val isWindows: Boolean
get() = platformName == "win" get() = platformName == "win"
@@ -110,7 +110,8 @@ open class NodeJsRootExtension(@Transient val rootProject: Project) : Configurat
nodeExecutable = getExecutable("node", nodeCommand, "exe"), nodeExecutable = getExecutable("node", nodeCommand, "exe"),
platformName = platform, platformName = platform,
architectureName = architecture, architectureName = architecture,
ivyDependency = getIvyDependency() ivyDependency = getIvyDependency(),
downloadBaseUrl = nodeDownloadBaseUrl
) )
} }
@@ -28,6 +28,9 @@ abstract class NodeJsSetupTask : DefaultTask() {
val ivyDependency: String val ivyDependency: String
@Input get() = env.ivyDependency @Input get() = env.ivyDependency
val downloadBaseUrl: String
@Input get() = env.downloadBaseUrl
val destination: File val destination: File
@OutputDirectory get() = env.nodeDir @OutputDirectory get() = env.nodeDir
@@ -41,16 +44,13 @@ abstract class NodeJsSetupTask : DefaultTask() {
@Suppress("unused") // as it called by Gradle before task execution and used to resolve artifact @Suppress("unused") // as it called by Gradle before task execution and used to resolve artifact
@get:Classpath @get:Classpath
val nodeJsDist: File val nodeJsDist: File by lazy {
get() {
@Suppress("UnstableApiUsage", "DEPRECATION")
val repo = project.repositories.ivy { repo -> val repo = project.repositories.ivy { repo ->
repo.name = "Node Distributions at ${settings.nodeDownloadBaseUrl}" repo.name = "Node Distributions at ${downloadBaseUrl}"
repo.url = URI(settings.nodeDownloadBaseUrl) repo.url = URI(downloadBaseUrl)
repo.patternLayout { repo.patternLayout {
it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") it.artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]")
it.ivy("v[revision]/ivy.xml")
} }
repo.metadataSources { it.artifact() } repo.metadataSources { it.artifact() }
repo.content { it.includeModule("org.nodejs", "node") } repo.content { it.includeModule("org.nodejs", "node") }
@@ -63,7 +63,7 @@ abstract class NodeJsSetupTask : DefaultTask() {
?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration) ?.report(NumericalMetrics.ARTIFACTS_DOWNLOAD_SPEED, dist.length() * 1000 / downloadDuration)
} }
project.repositories.remove(repo) project.repositories.remove(repo)
return dist dist
} }
init { init {
@@ -76,9 +76,9 @@ abstract class NodeJsSetupTask : DefaultTask() {
@Suppress("unused") @Suppress("unused")
@TaskAction @TaskAction
fun exec() { fun exec() {
logger.kotlinInfo("Using node distribution from '$_nodeJsDist'") logger.kotlinInfo("Using node distribution from '$nodeJsDist'")
unpackNodeArchive(_nodeJsDist, destination.parentFile) // parent because archive contains name already unpackNodeArchive(nodeJsDist, destination.parentFile) // parent because archive contains name already
if (!env.isWindows) { if (!env.isWindows) {
File(env.nodeExecutable).setExecutable(true) File(env.nodeExecutable).setExecutable(true)