[Gradle, JS] No specific handling of composite dependencies

^KT-47351 fixed
This commit is contained in:
Ilya Goncharov
2023-03-22 13:05:34 +00:00
committed by Space Team
parent 1bc299508a
commit 956682d1ca
11 changed files with 89 additions and 37 deletions
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.gradle.util.normalizePath
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.condition.DisabledIf
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.zip.ZipFile
import kotlin.io.path.*
@@ -85,26 +84,31 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
fun testJsCompositeBuild(gradleVersion: GradleVersion) {
project("js-composite-build", gradleVersion) {
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
gradleProperties.appendText(jsCompilerType(KotlinJsCompilerType.IR))
subProject("lib").apply {
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
gradleProperties.appendText(jsCompilerType(KotlinJsCompilerType.IR))
}
fun asyncVersion(rootModulePath: String, moduleName: String): String =
subProject("base").apply {
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
}
fun moduleVersion(rootModulePath: String, moduleName: String, pathToPackageJson: String): String =
NpmProjectModules(projectPath.resolve(rootModulePath).toFile())
.require(moduleName)
.let { Paths.get(it).parent.parent.resolve(NpmProject.PACKAGE_JSON) }
.let { Paths.get(it).parent.resolve(pathToPackageJson).resolve(NpmProject.PACKAGE_JSON) }
.let { fromSrcPackageJson(it.toFile()) }
.let { it!!.version }
build("build") {
val appAsyncVersion = asyncVersion("build/js/node_modules/js-composite-build", "async")
val appAsyncVersion = moduleVersion("build/js/node_modules/js-composite-build", "async", "..")
assertEquals("3.2.0", appAsyncVersion)
val libAsyncVersion = asyncVersion("build/js/node_modules/lib2", "async")
val libAsyncVersion = moduleVersion("build/js/node_modules/lib2", "async", "..")
assertEquals("2.6.2", libAsyncVersion)
val appDecamelizeVersion = moduleVersion("build/js/node_modules/base2", "decamelize", ".")
assertEquals("1.1.1", appDecamelizeVersion)
}
}
}
@@ -0,0 +1,38 @@
group = "com.example"
plugins {
kotlin("js") version "<pluginMarkerVersion>"
}
repositories {
mavenLocal()
mavenCentral()
}
kotlin.js {
nodejs()
browser()
}
tasks.named("browserTest") {
enabled = false
}
rootProject.tasks
.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class.java)
.named("kotlinNpmInstall")
.configure {
args.addAll(
listOf(
"--network-concurrency",
"1",
"--mutex",
"network"
)
)
}
dependencies {
implementation(kotlin("stdlib-js"))
implementation(npm("decamelize", "1.1.1"))
}
@@ -0,0 +1,15 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
}
plugins {
id "org.jetbrains.kotlin.js" version "$kotlin_version"
id "org.jetbrains.kotlin.test.fixes.android" version "$test_fixes_version"
}
}
rootProject.name = "base2"
@@ -34,5 +34,6 @@ rootProject.tasks
dependencies {
implementation(kotlin("stdlib-js"))
implementation("com.example:base2")
implementation(npm("async", "2.6.2"))
}
@@ -12,4 +12,6 @@ pluginManagement {
}
}
includeBuild("../base")
rootProject.name = "lib2"
@@ -1,5 +1,5 @@
object Singleton {
fun test(): Long {
return 42L
return answer()
}
}
@@ -182,6 +182,10 @@ internal open class ProcessedFilesCache(
file: File,
compute: () -> File?
): String? {
if (!file.exists()) {
return null
}
val hash = fileHasher.hash(file).toByteArray()
val old = state[hash]
@@ -91,13 +91,17 @@ class KotlinCompilationNpmResolver(
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
val aggregatedConfiguration: Configuration by lazy {
createAggregatedConfiguration()
}
private var _compilationNpmResolution: KotlinCompilationNpmResolution? = null
val compilationNpmResolution: KotlinCompilationNpmResolution
get() {
return _compilationNpmResolution ?: run {
val visitor = ConfigurationVisitor()
visitor.visit(createAggregatedConfiguration())
visitor.visit(aggregatedConfiguration)
visitor.toPackageJsonProducer()
}.also {
_compilationNpmResolution = it
@@ -212,12 +216,7 @@ class KotlinCompilationNpmResolver(
val artifactId = artifact.id
val componentIdentifier = artifactId.componentIdentifier
if (artifactId `is` CompositeProjectComponentArtifactMetadata) {
visitCompositeProjectDependency(dependency, componentIdentifier as ProjectComponentIdentifier)
return
}
if (componentIdentifier is ProjectComponentIdentifier) {
if (componentIdentifier is ProjectComponentIdentifier && !(artifactId `is` CompositeProjectComponentArtifactMetadata)) {
visitProjectDependency(componentIdentifier)
return
}
@@ -225,28 +224,6 @@ class KotlinCompilationNpmResolver(
externalGradleDependencies.add(ExternalGradleDependency(dependency, artifact))
}
private fun visitCompositeProjectDependency(
dependency: ResolvedDependency,
componentIdentifier: ProjectComponentIdentifier
) {
check(target is KotlinJsIrTarget) {
"""
Composite builds for Kotlin/JS are supported only for IR compiler.
Use kotlin.js.compiler=ir in gradle.properties or
js(IR) {
...
}
""".trimIndent()
}
(componentIdentifier as DefaultProjectComponentIdentifier).let { identifier ->
val includedBuild = project.gradle.includedBuild(identifier.identityPath.topRealPath().name!!)
internalCompositeDependencies.add(
CompositeDependency(dependency.moduleName, dependency.moduleVersion, includedBuild.projectDir, includedBuild)
)
}
}
private fun visitProjectDependency(
componentIdentifier: ProjectComponentIdentifier
) {
@@ -6,8 +6,10 @@
package org.jetbrains.kotlin.gradle.targets.js.npm.tasks
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.work.NormalizeLineEndings
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
@@ -74,6 +76,14 @@ abstract class KotlinPackageJsonTask :
.sorted()
}
@get:IgnoreEmptyDirectories
@get:NormalizeLineEndings
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
internal val aggregatedConfiguration: FileCollection by lazy {
compilationResolver.aggregatedConfiguration
}
// nested inputs are processed in configuration phase
// so npmResolutionManager must not be used
@get:Nested