I am currently trying to setup a gradle project using jsweet to automatically translate my java classes into typescript classes. I added the candy 'j4ts' so classes like 'ArrayList' for example are translated better in my typescript code. This works so far but now I have to use the 'commonjs' module of jsweet. Now ArrayList is still translated into typescript code but inside the ts file I get the error 'Cannot find name 'ArrayList'.'. I am still a beginner in this, so I may have overlooked something important but I couldn't find out the problem by googling etc. I hope you have an idea, thanks!

To understand better what I mean, here is my build.gradle file:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
        maven { url "https://repository.jsweet.org/artifactory/libs-release-local" }
        maven { url "https://repository.jsweet.org/artifactory/libs-snapshot-local" }
        maven { url "https://repository.jsweet.org/artifactory/plugins-release-local" }
        maven { url "https://repository.jsweet.org/artifactory/plugins-snapshot-local" }
    }
    dependencies {
        classpath('org.jsweet:jsweet-gradle-plugin:3.1.0') {
            transitive = true
        }
        classpath("com.github.node-gradle:gradle-node-plugin:5.0.0")
    }
}

plugins{
    id "com.github.node-gradle.node" version "5.0.0"
}


apply plugin: 'java'
apply plugin: 'org.jsweet.jsweet-gradle-plugin'
apply plugin: 'com.github.node-gradle.node'

//mainClassName = 'hello.HelloWorld'

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://repository.jsweet.org/artifactory/libs-snapshot-local" }
    maven { url "https://repository.jsweet.org/artifactory/libs-release-local" }
}

compileJava {
    enabled = false
}

jsweet {
    verbose = true
    encoding = 'UTF-8'
    sourceMap = true
    tsOnly = true
    tsOut = project.file('target/typescript')
    module = 'commonjs'
    moduleResolution = 'node'
    outDir = project.file('target/javascript')
    workingDir = project.file('target/workingDir')
    candiesJsOut = project.file('target/candies')
    targetVersion = 'ES6'
    includes = ['**/*.java']
}


node {
    download = true
    version = "12.18.2"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    implementation group: 'org.jsweet', name: 'jsweet-core', version: "6.3.0"
    implementation group: 'org.jsweet', name: 'j4ts', version: '2.0.0'
    testImplementation "junit:junit:4.12"
}



jar {
    archiveBaseName = 'gs-gradle'
    archiveVersion =  '0.1.0'
}

I tried to further configure jsweet in a way it would be accepting the classes provided by j4ts. The rest was trial and error which didn't help unfortunately. The only thing I noticed was that without the commonjs module the java code is translated as follows:

From ArrayList<String> test = new ArrayList<>();

Into const test: java.util.ArrayList<string> = <any>(new java.util.ArrayList<any>());

And with the commonjs module into: const test: ArrayList<string> = <any>(new ArrayList<any>());

0

There are 0 best solutions below