Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Create multiple js files

106 views
Skip to first unread message

Eugene Kamenev

unread,
Aug 11, 2024, 2:07:50 AM8/11/24
to TeaVM
Hello,

Is there an option to produce multiple js files in same project?
I tried to add simple task config in Gradle like this:

teavm {
  js {
    addedToWebApp = true
    mainClass = "com.github.JSApplication"
    moduleType = JSModuleType.NONE
    obfuscated = false
    optimization = OptimizationLevel.NONE
  }
}

task teamvmTemp(type: GenerateJavaScriptTask) {
     mainClass = "com.github.Temp"
     classpath = sourceSets.main.compileClasspath
     moduleType = JSModuleType.NONE
     obfuscated = false
     optimization = OptimizationLevel.NONE
     targetFileName = "temp.js"
     outputDir = file("build/teavm")
}

When invoked for teamvmTemp  task it fails with error like this:
There's no main class: 'com.github.Temp'

Thank you.

Alexey Andreev

unread,
Aug 12, 2024, 6:52:56 AM8/12/24
to te...@googlegroups.com


teavm {
  js {
    addedToWebApp = true
    mainClass = "com.github.JSApplication"
    moduleType = JSModuleType.NONE
    obfuscated = false
    optimization = OptimizationLevel.NONE
  }
}

task teamvmTemp(type: GenerateJavaScriptTask) {
     mainClass = "com.github.Temp"
     classpath = sourceSets.main.compileClasspath
     moduleType = JSModuleType.NONE
     obfuscated = false
     optimization = OptimizationLevel.NONE
     targetFileName = "temp.js"
     outputDir = file("build/teavm")
}

When invoked for teamvmTemp  task it fails with error like this:
There's no main class: 'com.github.Temp'

Hello. Sure, you didn't specify any dependency to Java compiler task, so teamvmTemp task has no idea that it should run after Java compiler. You need to specify dependency. Or, you can use something like that:

classpath.from sourceSets.main.output
classpath.from sourceSets.main.compileClasspath
so that task dependency will be added automatically

James Moliere

unread,
Aug 18, 2024, 7:47:11 PM8/18/24
to TeaVM
Where is the 'GenerateJavaScriptTask' coming from? 

Alexey Andreev

unread,
Aug 19, 2024, 4:57:13 PM8/19/24
to TeaVM
Where is the 'GenerateJavaScriptTask' coming from? 
 
It's installed by plugin. Or did you mean something else?

James Moliere

unread,
Aug 24, 2024, 12:58:43 PM8/24/24
to TeaVM

In my build.gradle file I have...
----------------------------------------------------------------------------------------
plugins {
...
id "org.teavm" version "0.10.1"
}

dependencies {
  teavm( teavm.libs.jso )
...
}

teavm {
js {
mainClass.set("teavm.Main")
sourceMap.set(true)
obfuscated.set(false)
debugInformation.set(true)
sourceMap.set(true)
targetFileName.set("main.js")
addedToWebApp = true
preservedClasses = [ "teavm.ItemListView" ]
}
}


task teamvmTemp(type: GenerateJavaScriptTask) {
mainClass = "com.github.Temp" // I'll use this for now.
classpath.from = sourceSets.main.compileClasspath
classpath.from sourceSets.main.output

moduleType = JSModuleType.NONE
obfuscated = false
optimization = OptimizationLevel.NONE
targetFileName = "temp.js"
outputDir = file("build/teavm")
}
---------------------------------

With the output error...
A problem occurred evaluating project ':app'.
> Could not get unknown property 'GenerateJavaScriptTask' for project ':app' of type org.gradle.api.Project.

Do I need to add something else?
Reply all
Reply to author
Forward
0 new messages