Search code examples
gradlekotlinquasar

Kotlin Quasar example not working


I am testing the Kotlin Quasar actor example. Quasar and Kotlin – a Powerful Match So the question is, is this example out of date and is there any documentation in which I can find out how to use Kotlin and Quasar?

This is my gradle.build file.

group 'no.inmeta.kotlin.akka'
version '1.0-SNAPSHOT'

buildscript {
  ext.kotlin_version = '1.0.1'

repositories {
    mavenCentral()
}

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 }
}
apply plugin: 'kotlin'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "co.paralleluniverse:quasar-kotlin:0.7.4"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

Solution

  • I'm part of the Quasar team.

    The post cites Quasar tests which you can run by cloning the Quasar repo and running e.g. gradle :quasar-kotlin:build (requires Gradle installed) but for new projects/experiments I suggest to start instead from the Gradle template, kotlin branch which now uses the latest Kotlin 1.0.1-2 (and for simplicity the latest Quasar 0.7.5-SNAPSHOT that depends on it).

    Starting from that template I built this project (more info about how to configure it and run it in the main README) that runs the same Quasar actor tests as normal programs rather than tests. Here's its build.gradle:

    group 'no.inmeta.kotlin.akka'
    version '1.0-SNAPSHOT'
    
    buildscript {
        ext.kotlinVer = '1.0.1-2'
    
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVer"
        }
    }
    
    apply plugin: 'kotlin'
    apply plugin: 'application'
    
    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
    
    sourceCompatibility = 1.8     // 1.7
    targetCompatibility = 1.8     // 1.7
    
    configurations {
        quasar
    }
    
    configurations.all {
        resolutionStrategy {
            failOnVersionConflict()
        }
    }
    
    repositories {
    //    mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/releases" }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    //    maven { url 'https://maven.java.net/content/repositories/snapshots' }
    }
    
    ext.classifier = ':jdk8' // ':'
    
    ext.quasarVer  = '0.7.5-SNAPSHOT'
    
    dependencies {
        compile "co.paralleluniverse:quasar-core:${quasarVer}${classifier}"
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVer"
        compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVer"
        compile "co.paralleluniverse:quasar-kotlin:${quasarVer}"
    
        quasar "co.paralleluniverse:quasar-core:${quasarVer}${classifier}@jar"
    }
    
    applicationDefaultJvmArgs = [
        "-Dco.paralleluniverse.fibers.verifyInstrumentation=true",
        "-Dco.paralleluniverse.fibers.detectRunawayFibers=false",
        "-javaagent:${configurations.quasar.singleFile}" // =v, =d
    ]
    
    // mainClassName = 'co.paralleluniverse.kotlin.actors1.PingPongKt'
    mainClassName = 'co.paralleluniverse.kotlin.actors2.PingPongWithDeferKt'
    
    task wrapper(type: Wrapper) {
        gradleVersion = '2.12'
    }
    
    defaultTasks 'run'
    

    Some notes about the differences with your build file:

    • Since I converted the tests to programs, I'm including the application plugin and its configuration (here, applicationDefaultJvmArgs and mainClassName) as well as setting the default Gradle task to run.
    • In addition to the above, a gradle wrapper has been generated and pushed so that ./gradlew is all you need on the command line, with no need to have a local Gradle installation (how to run it in an IDE depends on the IDE).
    • You need to run the Quasar agent (or AoT instrumentation but using the agent here) so there's a quasar configuration pointing to the artifact that is then used to pass the -javaagent:${configurations.quasar.singleFile} JVM argument.
    • Using Java 8 as Quasar has a specific optimized build for it.

    Also note that there is now a 1.0 branch of the quasar-kotlin-jetbrains-webinar project (which is now the HEAD one in fact), which contains the companion source code of this guest webinar with IntelliJ, ported to the latest Kotlin and Quasar as well.

    Let me know if this helps.