Carter
04/16/2023, 1:23 PMbrowser-app
which produces the JavaScript browser app, while server-app
is a JVM Ktor application that serves the JavaScript from browser-app to clients. I’ve created configurations in the browser-app, which are consumed by server-app by following these Gradle instructions.
Recently I’ve started seeing two problems:
1. Sometimes the Javascript is not bundled into server-app which makes me think the dependency between browser-app and server-app isn’t quite right
2. I sometimes also see the error Reason: Task ':server-app:startScripts' uses this output of task ':browser-app:jsBrowserDistribution' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
How can I troubleshoot this further?Carter
04/16/2023, 1:25 PMconfigurations.register("browserAppDevelopment") {
isCanBeConsumed = true
isCanBeResolved = false
}.also { configuration ->
artifacts {
val task = tasks.getByName("jsBrowserDevelopmentExecutableDistribution")
task.outputs.files.forEach {
add(configuration.name, it) {
builtBy(task)
}
}
}
}
configurations.register("browserAppProduction") {
isCanBeConsumed = true
isCanBeResolved = false
}.also { configuration ->
artifacts {
val resourcesTask = tasks.getByName("jsBrowserProductionExecutableDistributeResources")
resourcesTask.outputs.files.forEach { file ->
add(configuration.name, file) {
builtBy(resourcesTask)
}
}
val webpackTask = tasks.getByName("jsBrowserProductionWebpack")
webpackTask.outputs.files.filter { it.name == javascriptAppFilename }.forEach { file ->
add(configuration.name, file) {
builtBy(webpackTask)
}
}
}
}
server-app/build.gradle.kts
kotlin {
jvm {
withJava()
jvm()
}
sourceSets {
getByName("jvmMain") {
dependencies {
if (isJavascriptMinificationEnabled) {
implementation(
project(
mapOf(
"path" to ":browser-app",
"configuration" to "browserAppProduction"
)
)
)
} else {
implementation(
project(
mapOf(
"path" to ":browser-app",
"configuration" to "browserAppDevelopment"
)
)
)
}
}
}
}
}
tapchicoma
04/17/2023, 7:55 AMIlya Goncharov [JB]
04/17/2023, 10:31 AMjsBrowserDistribution
task for browserAppProduction
. As I can see for browserAppDevelopment
you use output of distribution
task, but for production one you don’t use it, but as I understand, you can.
As for jsBrowserProductionWebpack
, there is no js
file output for this task anymore. Now there is output directory for webpack output (because webpack could emit more than 1 file). That’s why this filter filter { it.name == javascriptAppFilename }
can filter out all outputsCarter
04/17/2023, 7:45 PMIlya Goncharov [JB]
04/17/2023, 7:50 PMCarter
04/17/2023, 7:50 PMCarter
04/17/2023, 7:50 PMapplication
plugin?Carter
04/17/2023, 7:53 PMA problem was found with the configuration of task ':server-app:startScripts' (type 'CreateStartScripts').
- Gradle detected a problem with the following location: 'build/js/packages/Chat-browser-app/webpack.config.js'.
Reason: Task ':server-app:startScripts' uses this output of task ':browser-app:jsBrowserDevelopmentWebpack' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
Possible solutions:
1. Declare task ':browser-app:jsBrowserDevelopmentWebpack' as an input of ':server-app:startScripts'.
2. Declare an explicit dependency on ':browser-app:jsBrowserDevelopmentWebpack' from ':server-app:startScripts' using Task#dependsOn.
3. Declare an explicit dependency on ':browser-app:jsBrowserDevelopmentWebpack' from ':server-app:startScripts' using Task#mustRunAfter.