Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate integration-testing module from Groovy to Kts #4341

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

DmitryTsyvtsyn
Copy link

No description provided.

Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the proposed changes, I get the following Gradle error (for example, when invoking ./gradle tasks in the integration-testing directory):

Build file `kotlinx.coroutines/integration-testing/build.gradle.kts' line: 34

'kotlin_snapshot_version' should be defined when building with snapshot compiler

On develop, everything is okay, so there's a clear regression.

When I look at build.gradle and build.gradle.kts, there's a clear change in logic.

Such mistakes will be easier to avoid (and if they do happen, to pinpoint) if the refactoring is split into several commits:

  • Rename *.gradle into *.gradle.kts (the build is expected to fail due to the incorrect syntax).
  • Rewrite the syntax to be correct, but stay as faithful as possible to the original (so that all the changes are trivial).
  • Introduce the extra structure if you want.

This is just a suggestion, though. I'll accept this PR as is when it's fixed, as it's quite small and easy to verify with any approach.

@DmitryTsyvtsyn DmitryTsyvtsyn force-pushed the migrate-integration-testing-to-kts branch 2 times, most recently from 50d6d83 to c7f7463 Compare January 28, 2025 13:03
@DmitryTsyvtsyn
Copy link
Author

I updated the pull request

Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the remaining change in behavior, I think this is good to go. There are still minor things that could be improved in terms of style. Would you like me to list them, or should we merge this PR, and then I'll put my fixes on top of it in a separate PR myself?

}

plugins {
id("org.jetbrains.kotlin.jvm") version "2.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.0.0 is incorrect, it must be the configured Kotlin version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll correct it

@DmitryTsyvtsyn
Copy link
Author

Other than the remaining change in behavior, I think this is good to go. There are still minor things that could be improved in terms of style. Would you like me to list them, or should we merge this PR, and then I'll put my fixes on top of it in a separate PR myself?

Give me a list of minor things, I'll correct it along with the Kotlin version

val kotlinVersion = fetchKotlinVersion()

extra.apply {
set("native_targets_enabled", isEnabledNativeTargets)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is unused, so no need to set or check it.

val isEnabledNativeTargets = rootProject.properties["disable_native_targets"] == null
val usingSnapshotVersion = checkIsSnapshotVersion()
val hasSnapshotTrainProperty = checkIsSnapshotTrainProperty()
val kotlinVersion = fetchKotlinVersion()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is only used to set kotlin_version, which is only used in this build script. Both fetchKotlinVersion and this val can be moved outside the buildScript block.

}
}

tasks.create<Test>("jvmCoreTest") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By giving a name to this, you can refer to the newly-created task without using the "jvmCoreTest" string below. The same goes for the other tasks.

}
}

tasks.named<KotlinCompile>("compileDebugAgentTestKotlin") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting from this line, all of this could be put into a tasks block, so that there's no need to repeat tasks. everywhere.

}

// Drop this when node js version become stable
tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class.java).configureEach {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask::class.java).configureEach {
tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {

By importing the class name, the code becomes even more readable. The same goes for all the other tasks.withType( invocations.

}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile::class.java).configureEach {
jvmTargetValidationMode = org.jetbrains.kotlin.gradle.dsl.jvm.JvmTargetValidationMode.WARNING
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would benefit from importing the name.

Comment on lines +87 to +89
val nodeJsRootExtension = rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java)
nodeJsRootExtension?.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
nodeJsRootExtension?.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then

Suggested change
val nodeJsRootExtension = rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java)
nodeJsRootExtension?.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
nodeJsRootExtension?.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
rootProject.extensions.findByType<NodeJsRootExtension>()?.let {
it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}

(after adding an import statement). Perfectly readable even without the redundant repetition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants