lgrignon / jsweet-gradle-plugin

Brings the power of JSweet to Gradle
Apache License 2.0
17 stars 15 forks source link

candies not being packaged with JS output #8

Closed IgorBelyayev closed 6 years ago

IgorBelyayev commented 7 years ago

Whenever I transpile with the plugin, my candies do not get included in the resulting bundle. For example, I'm using the j4ts candy. In my transpiled bundle, calling functions in j4ts crashes because it cannot locate them. Should the candy's Javascript be included in the resulting bundle or am I missing something? I've pasted my build.gradle below:

apply plugin: 'java'
apply plugin: 'org.jsweet.jsweet-gradle-plugin'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()

    // jsweet
    maven { url "http://repository.jsweet.org/artifactory/libs-release-local" }
    maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
    maven { url "http://repository.jsweet.org/artifactory/plugins-release-local" }
    maven { url "http://repository.jsweet.org/artifactory/plugins-snapshot-local" }
    maven { url "http://google-diff-match-patch.googlecode.com/svn/trunk/maven" }
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.12'
    testCompile 'junit:junit:4.12'
    testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
    testCompile group: 'com.google.guava', name: 'guava', version: '22.0'

    compile group: 'org.jsweet.candies', name: 'jsweet-core', version:'1.2.0-20161222'
    compile group: 'org.jsweet', name: 'jsweet-transpiler', version:'2.0.0-SNAPSHOT'
    compile group: 'org.jsweet.candies', name: 'j4ts', version:'0.3.1'
}

buildscript {
    repositories {
        mavenCentral()
        maven { url "http://repository.jsweet.org/artifactory/libs-release-local" }
        maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
        maven { url "http://repository.jsweet.org/artifactory/plugins-release-local" }
        maven { url "http://repository.jsweet.org/artifactory/plugins-snapshot-local" }
        maven { url "http://google-diff-match-patch.googlecode.com/svn/trunk/maven" }
    }
    dependencies {
        classpath('org.jsweet:jsweet-gradle-plugin:1.2.1-SNAPSHOT') { //
            transitive = true }
    }
}

jsweet {
    verbose = true
    encoding = 'UTF-8'
    sourceMap = false
    bundle = true
    targetVersion = 'ES5'
}
lgrignon commented 7 years ago

Hello @IgorBelyayev I am sorry I answer this late I didn't catch this issue's notification.

Basically, to extract the JavaScript from a candy which have JavaScript sources, you juste have to set the candiesJsOut option (please refer to the JSweet maven plugin documentation for a comprehensive documentation of the options). I added this option to the Gradle plugin's documentation, but the following code should do the trick:

jsweet {
    verbose = true
    encoding = 'UTF-8'
    sourceMap = false
    bundle = true
    targetVersion = 'ES5'
    candiesJsOut = new File('target/candies')
}

Additionally, you shouldn't mix JSweet 1.x and 2.x versions, you declared

    compile group: 'org.jsweet', name: 'jsweet-transpiler', version:'2.0.0-SNAPSHOT'

but use another version in your buildScript section:

buildscript {
    // ...
    dependencies {
        classpath('org.jsweet:jsweet-gradle-plugin:1.2.1-SNAPSHOT') { //
            transitive = true }
    }
}

You should try starting your build.gradle from the examples (which use the latest Gradle plugin). Anyway I think I fixed your build.gradle, you could give it a try if you want:

apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use 'jcenter' for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()

    // jsweet
    maven { url "http://repository.jsweet.org/artifactory/libs-release-local" }
    maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
    maven { url "http://repository.jsweet.org/artifactory/plugins-release-local" }
    maven { url "http://repository.jsweet.org/artifactory/plugins-snapshot-local" }
    maven { url "http://google-diff-match-patch.googlecode.com/svn/trunk/maven" }
}

// In this section you declare the dependencies for your production and test code
dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.12'
    testCompile 'junit:junit:4.12'
    testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
    testCompile group: 'com.google.guava', name: 'guava', version: '22.0'

    compile group: 'org.jsweet.candies', name: 'jsweet-core', version:'1.2.0-SNAPSHOT'
    compile group: 'org.jsweet', name: 'jsweet-transpiler', version:"1.2.1-SNAPSHOT"
    compile group: 'org.jsweet.candies', name: 'j4ts', version:'0.3.1'
}

buildscript {
    repositories {
        mavenCentral()
        maven { url "http://repository.jsweet.org/artifactory/libs-release-local" }
        maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
        maven { url "http://repository.jsweet.org/artifactory/plugins-release-local" }
        maven { url "http://repository.jsweet.org/artifactory/plugins-snapshot-local" }
        maven { url "http://google-diff-match-patch.googlecode.com/svn/trunk/maven" }
    }
    dependencies {
        classpath('org.jsweet:jsweet-gradle-plugin:1.2.1-SNAPSHOT') { //
            transitive = true }
    }
}

apply plugin: 'org.jsweet.jsweet-gradle-plugin'

jsweet {
    verbose = true
    encoding = 'UTF-8'
    sourceMap = false
    bundle = true
    targetVersion = 'ES5'
    // transpiled TS and JS will be output in the default directory: ".ts" and "js"
    // and extracted JavaScript will go in 'target/candies'
    candiesJsOut = new File('target/candies')
}

Hope this helped. Please close issue if this is ok for you :)

lgrignon commented 7 years ago

@IgorBelyayev Is everything ok for you?