Skip to content

Build with Gradle

Volker Berlin edited this page Dec 29, 2019 · 9 revisions

Build with Gradle

Load the compiler Gradle plugin

Until there is a stable version of JWebAssembly we recommended the snapshot version. Declare the repository and classpath of the plugin first.

buildscript {
    repositories {
        maven { url uri('https://jitpack.io') }
    }
    dependencies {
        classpath 'com.github.i-net-software:jwebassembly-gradle:master-SNAPSHOT'
    }
}

And apply the plugin to load it.

apply plugin: 'de.inetsoftware.jwebassembly'

This implicit apply the Java plugin. We want compile Java sources first and the compile it to the WebAssembly files.

Library Dependencies

Add the library dependencies. Here also the snapshot version of the JWebAssembly API is recommended currently. You can also add other Java libraries that you need. If there calls into libraries then the needed Java code will be compiled.

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.i-net-software:jwebassembly-api:master-SNAPSHOT'
}

Wasm file name

Like in Java you can optional define a custom file name for the output:

archivesBaseName = 'HelloWorld'

Source files

Like in Java you can optional define the source files that want compile if you does not use the defaults. Resources are not supported yet.

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
        }
    }
}

wasm task

The wasm files will be build from the wasm task. A complete list of all properties can you find in the source code of the wasm task.

wasm {
  //Get more debug information if there are problems.
  //logging.level = LogLevel.DEBUG

  //Change the output format to the text format *.wat. 
  //This can be helpful to understand the problems if you see the generated code as text format.
  //format = 'text'

  //The used JWebAssembly compiler version. The default is the latest release '+'. 
  //You can set any valid Gradle version string or a full dependency string. 
  //The snapshot version is recommended until a stable release.
  //compilerVersion = 0.2
  compilerVersion = 'com.github.i-net-software:jwebassembly:master-SNAPSHOT'

  //Write method and parameter names into the output *.wasm file. 
  //The file will be approximate 10% larger. And it generate a source map. 
  //With a source map you can see in the debugger of the browser your source code if available.
  debugNames = true
}
Clone this wiki locally