[Gradle, JS] No specific handling of composite dependencies
^KT-47351 fixed
This commit is contained in:
committed by
Space Team
parent
1bc299508a
commit
956682d1ca
+11
-7
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.gradle.util.normalizePath
|
|||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import org.junit.jupiter.api.condition.DisabledIf
|
import org.junit.jupiter.api.condition.DisabledIf
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
@@ -85,26 +84,31 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
|
|||||||
fun testJsCompositeBuild(gradleVersion: GradleVersion) {
|
fun testJsCompositeBuild(gradleVersion: GradleVersion) {
|
||||||
project("js-composite-build", gradleVersion) {
|
project("js-composite-build", gradleVersion) {
|
||||||
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
||||||
gradleProperties.appendText(jsCompilerType(KotlinJsCompilerType.IR))
|
|
||||||
|
|
||||||
subProject("lib").apply {
|
subProject("lib").apply {
|
||||||
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
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())
|
NpmProjectModules(projectPath.resolve(rootModulePath).toFile())
|
||||||
.require(moduleName)
|
.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 { fromSrcPackageJson(it.toFile()) }
|
||||||
.let { it!!.version }
|
.let { it!!.version }
|
||||||
|
|
||||||
build("build") {
|
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)
|
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)
|
assertEquals("2.6.2", libAsyncVersion)
|
||||||
|
|
||||||
|
val appDecamelizeVersion = moduleVersion("build/js/node_modules/base2", "decamelize", ".")
|
||||||
|
assertEquals("1.1.1", appDecamelizeVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+38
@@ -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"))
|
||||||
|
}
|
||||||
+15
@@ -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"
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fun answer() = 42L
|
||||||
+1
@@ -34,5 +34,6 @@ rootProject.tasks
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib-js"))
|
implementation(kotlin("stdlib-js"))
|
||||||
|
implementation("com.example:base2")
|
||||||
implementation(npm("async", "2.6.2"))
|
implementation(npm("async", "2.6.2"))
|
||||||
}
|
}
|
||||||
+2
@@ -12,4 +12,6 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
includeBuild("../base")
|
||||||
|
|
||||||
rootProject.name = "lib2"
|
rootProject.name = "lib2"
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
object Singleton {
|
object Singleton {
|
||||||
fun test(): Long {
|
fun test(): Long {
|
||||||
return 42L
|
return answer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -182,6 +182,10 @@ internal open class ProcessedFilesCache(
|
|||||||
file: File,
|
file: File,
|
||||||
compute: () -> File?
|
compute: () -> File?
|
||||||
): String? {
|
): String? {
|
||||||
|
if (!file.exists()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
val hash = fileHasher.hash(file).toByteArray()
|
val hash = fileHasher.hash(file).toByteArray()
|
||||||
val old = state[hash]
|
val old = state[hash]
|
||||||
|
|
||||||
|
|||||||
+6
-29
@@ -91,13 +91,17 @@ class KotlinCompilationNpmResolver(
|
|||||||
|
|
||||||
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
|
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
|
||||||
|
|
||||||
|
val aggregatedConfiguration: Configuration by lazy {
|
||||||
|
createAggregatedConfiguration()
|
||||||
|
}
|
||||||
|
|
||||||
private var _compilationNpmResolution: KotlinCompilationNpmResolution? = null
|
private var _compilationNpmResolution: KotlinCompilationNpmResolution? = null
|
||||||
|
|
||||||
val compilationNpmResolution: KotlinCompilationNpmResolution
|
val compilationNpmResolution: KotlinCompilationNpmResolution
|
||||||
get() {
|
get() {
|
||||||
return _compilationNpmResolution ?: run {
|
return _compilationNpmResolution ?: run {
|
||||||
val visitor = ConfigurationVisitor()
|
val visitor = ConfigurationVisitor()
|
||||||
visitor.visit(createAggregatedConfiguration())
|
visitor.visit(aggregatedConfiguration)
|
||||||
visitor.toPackageJsonProducer()
|
visitor.toPackageJsonProducer()
|
||||||
}.also {
|
}.also {
|
||||||
_compilationNpmResolution = it
|
_compilationNpmResolution = it
|
||||||
@@ -212,12 +216,7 @@ class KotlinCompilationNpmResolver(
|
|||||||
val artifactId = artifact.id
|
val artifactId = artifact.id
|
||||||
val componentIdentifier = artifactId.componentIdentifier
|
val componentIdentifier = artifactId.componentIdentifier
|
||||||
|
|
||||||
if (artifactId `is` CompositeProjectComponentArtifactMetadata) {
|
if (componentIdentifier is ProjectComponentIdentifier && !(artifactId `is` CompositeProjectComponentArtifactMetadata)) {
|
||||||
visitCompositeProjectDependency(dependency, componentIdentifier as ProjectComponentIdentifier)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (componentIdentifier is ProjectComponentIdentifier) {
|
|
||||||
visitProjectDependency(componentIdentifier)
|
visitProjectDependency(componentIdentifier)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -225,28 +224,6 @@ class KotlinCompilationNpmResolver(
|
|||||||
externalGradleDependencies.add(ExternalGradleDependency(dependency, artifact))
|
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(
|
private fun visitProjectDependency(
|
||||||
componentIdentifier: ProjectComponentIdentifier
|
componentIdentifier: ProjectComponentIdentifier
|
||||||
) {
|
) {
|
||||||
|
|||||||
+10
@@ -6,8 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.npm.tasks
|
package org.jetbrains.kotlin.gradle.targets.js.npm.tasks
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.provider.Property
|
import org.gradle.api.provider.Property
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
|
import org.gradle.work.NormalizeLineEndings
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
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.NodeJsRootExtension
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||||
@@ -74,6 +76,14 @@ abstract class KotlinPackageJsonTask :
|
|||||||
.sorted()
|
.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
|
// nested inputs are processed in configuration phase
|
||||||
// so npmResolutionManager must not be used
|
// so npmResolutionManager must not be used
|
||||||
@get:Nested
|
@get:Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user