Gradle Plugins

We developed two gradle plugins (jawa-plugin and android-jawa-plugin) for allowing Jawa language to build with java and android program.

The Jawa Plugin

The Jawa plugin extends the Java plugin to add support for Jawa projects. It can deal with Jawa code, mixed Jawa and Java code, and even pure Java code (although we don’t necessarily recommend to use it for the latter). The plugin supports joint compilation, which allows you to freely mix and match Jawa and Java code, with dependencies in both directions. For example, a Jawa class can extend a Java class that in turn extends a Jawa class. This makes it possible to use the best language for the job, and to rewrite any class in the other language if needed.

Usage

To use the Jawa plugin, include the following in your build script:

Build script snippet for use in all Gradle versions:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.github.arguslab:gradle-jawa-plugin:VERSION"
  }
}

apply plugin: "org.argus.jawa"

dependencies {
    compile "com.github.arguslab:jawa-compiler_2.11:VERSION"
}

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {
  id "org.argus.jawa" version "VERSION"
}

dependencies {
    compile "com.github.arguslab:jawa-compiler_2.11:VERSION"
}

Tasks

The Jawa plugin adds the following tasks to the project.

Table 1: Jawa plugin - tasks

Task name Depends on Description
compileJawa compileJava Compiles production Jawa source files.
compileTestJawa compileTestJava Compiles test Jawa source files.
compileSourceSetJawa compileSourceSetJava Compiles the given source set’s Jawa source files.

Table 2: Jawa plugin - additional task dependencies

Task name Depends on
classes compileJawa
testClasses compileTestJawa
sourceSetClasses compileSourceSetJawa

Figure: Jawa plugin - tasks

TBA

Project layout

The Jawa plugin assumes the project layout shown in Table 3. All the Jawa source directories can contain Jawa and Java code. The Java source directories may only contain Java source code. None of these directories need to exist or have anything in them; the Jawa plugin will simply compile whatever it finds.

Table 3: Jawa plugin - project layout

Directory Meaning
src/main/java Production Java source
src/main/resources Production resources
src/main/jawa Production Jawa sources. May also contain Java sources for joint compilation.
src/test/java Test Java source
src/test/resources Test resources
src/test/jawa Test Jawa sources. May also contain Java sources for joint compilation.
src/sourceSet/java Java source for the given source set
src/sourceSet/resources Resources for the given source set
src/sourceSet/jawa Jawa sources for the given source set. May also contain Java sources for joint compilation.

Changing the project layout

Just like the Java plugin, the Jawa plugin allows you to configure custom locations for Jawa production and test sources.

sourceSets {
    main {
        jawa {
            srcDirs = ['src/jawa'] // default: "src/main/jawa"
        }
    }

    test {
        jawa {
            srcDirs = ['test/jawa'] // default: "src/test/jawa"
        }
    }
}

The Android Jawa Plugin

The Android Jawa plugin extends the Android plugin to add support for Android projects.

Usage

To use the Jawa plugin, include the following in your build script:

Build script snippet for use in all Gradle versions:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.github.arguslab:gradle-android-jawa-plugin:VERSION"
  }
}

apply plugin: "org.argus.android-jawa"

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {
  id "org.argus.android-jawa" version "VERSION"
}

Changing the project layout

Just like the Android plugin, the Android Jawa plugin allows you to configure custom locations for Jawa production and test sources.

android {
    sourceSets {
        main {
            scala {
                srcDir ['src/jawa'] // default: "src/main/jawa"
            }
        }

        androidTest {
            scala {
                srcDir ['androidTest/jawa'] // default: "src/androidTest/jawa"
            }
        }
    }
}

Complete example

build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'gradle.plugin.com.github.arguslab:gradle-android-jawa-plugin:1.0.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'org.argus.android-jawa'

android {
    compileSdkVersion 19
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.fgwei.test"
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.0'
}