gradle - Kotlin Quasar 示例不起作用

标签 gradle kotlin quasar

我正在测试 Kotlin Quasar actor 示例。 Quasar and Kotlin – a Powerful Match 所以问题是,这个例子是否已经过时了?是否有任何文档可以让我了解如何使用 Kotlin 和 Quasar?

这是我的 gradle.build 文件。

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"
}

最佳答案

我是 Quasar 团队的一员。

这篇文章引用了 Quasar 测试,您可以通过克隆 Quasar 存储库并运行例如gradle :quasar-kotlin:build (需要安装 Gradle),但对于新项目/实验,我建议从 Gradle template, kotlin branch 开始现在使用最新的 Kotlin 1.0.1-2(为了简单起见,使用依赖于它的最新 Quasar 0.7.5-SNAPSHOT)。

从我构建的模板开始 this project (有关如何配置它并在主自述文件中运行它的更多信息)运行与普通程序相同的 Quasar actor 测试而不是测试。这是它的 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'

关于构建文件差异的一些注释:

  • 由于我将测试转换为程序,因此我将 application 插件及其配置(此处为 applicationDefaultJvmArgsmainClassName)包含为以及将默认 Gradle 任务设置为 run
  • 除了上述内容之外,还生成并推送了 gradle 包装器,因此您在命令行上只需使用 ./gradlew 即可,无需本地 Gradle 安装(如何在 IDE 中运行它取决于 IDE)。
  • 您需要运行 Quasar 代理(或 AoT 工具,但在此处使用代理),因此有一个 quasar 配置指向工件,然后用于传递 -javaagent:$ {configurations.quasar.singleFile} JVM 参数。
  • 使用 Java 8 作为 Quasar,它有一个特定的优化构建。

另请注意,现在有一个 1.0 branch of the quasar-kotlin-jetbrains-webinar project (实际上现在是 HEAD ),其中包含 this guest webinar with IntelliJ 的配套源代码,也移植到最新的 Kotlin 和 Quasar。

请告诉我这是否有帮助。

关于gradle - Kotlin Quasar 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36719303/

相关文章:

java - 为什么在使用 gradle 的子项目中使用时缺少 jackson 库依赖项?

gradle - Gradle以编程方式获取依赖项而无需配置

Gradle 依赖项 : compile using local jar vs compile from maven repository?

gradle - 当我升级到 Kotlin 1.3.30 时,为什么 Kotlin JSR223 脚本停止工作

android - 无法使用 Android Gradle 插件 3.0.1 解决 assembleAndroidTest 任务的依赖关系

java - 在 Quasar 中调度任务,无需生成新线程

vue.js - Quasar从axios上传文件

android - JaCoCo Gradle - 排除类并覆盖包含

kotlin + junit 5 -assertAll 用法

vue.js - 使用 Quasar (Vue) 进行服务器端输入验证