无法解析 GPars/Groovy 上的 DataflowVariable 类。

huangapple go评论59阅读模式
英文:

unable to resolve class DataflowVariable on GPars/Groovy

问题

我是Groovy/GPars的新手。我尝试运行以下文档中的示例代码(http://gpars.org/1.0.0/guide/guide/dataflow.html):

    import static groovyx.gpars.dataflow.Dataflow.task
    final def x = new DataflowVariable()
    final def y = new DataflowVariable()
    final def z = new DataflowVariable()
    
    task {
        z << x.val + y.val
    }
    
    task {
        x << 10
    }
    
    task {
        y << 5
    }
    
    println "Result: ${z.val}"

我的build.gradle文件具有以下依赖项/配置:

    plugins {
        id 'groovy'
    }
    
    group 'org.example'
    version '1.0-SNAPSHOT'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'org.apache.groovy:groovy:4.0.2'
        implementation group: 'org.codehaus.gpars', name: 'gpars', version: '1.0.0' //1.2.1
        implementation "org.codehaus.jsr166-mirror:jsr166y:1.7.0"
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
    }

但是当我运行我的文件时,我得到错误信息“无法解析类DataflowVariable”。
我尝试将gpars版本更改为1.0.0,以与以下文档相对应:http://gpars.org/1.0.0/guide/guide/dataflow.html

对于DataflowVariable,我没有其他导入问题,例如“groovyx.gpars.dataflow.stream.DataflowStream”,所以我不明白为什么会出现这个错误。

英文:

I am a beginner in Groovy/GPars. I am trying to run the example code from the following documentation (http://gpars.org/1.0.0/guide/guide/dataflow.html):

import static groovyx.gpars.dataflow.Dataflow.task
final def x = new DataflowVariable()
final def y = new DataflowVariable()
final def z = new DataflowVariable()

task {
    z << x.val + y.val
}

task {
    x << 10
}

task {
    y << 5
}

println "Result: ${z.val}"

My build.gradle file has the following dependencies/configuration:

    plugins {
    id 'groovy'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.apache.groovy:groovy:4.0.2'
    implementation group: 'org.codehaus.gpars', name: 'gpars', version: '1.0.0' //1.2.1
    implementation "org.codehaus.jsr166-mirror:jsr166y:1.7.0"
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

But when I run my file, I obtain the error "unable to resolve class DataflowVariable".
I have tried to change the gpars version to 1.0.0 to correspond with the following documentation: http://gpars.org/1.0.0/guide/guide/dataflow.html

I have no issues with other imports such as "groovyx.gpars.dataflow.stream.DataflowStream", so I don't understand why I have this error for DataflowVariable.

答案1

得分: 1

@cfrick的评论是正确的,你缺少了import groovyx.gpars.dataflow.DataflowVariable

import static groovyx.gpars.dataflow.Dataflow.task
import groovyx.gpars.dataflow.DataflowVariable

final def x = new DataflowVariable()
final def y = new DataflowVariable()
final def z = new DataflowVariable()

task {
    z << x.val + y.val
}

task {
    x << 10
}

task {
    y << 5
}

println "Result: ${z.val}"

Groovy Web Console中尝试它。

英文:

@cfrick's comment was right you were missing the import groovyx.gpars.dataflow.DataflowVariable

import static groovyx.gpars.dataflow.Dataflow.task
import groovyx.gpars.dataflow.DataflowVariable

final def x = new DataflowVariable()
final def y = new DataflowVariable()
final def z = new DataflowVariable()

task {
    z &lt;&lt; x.val + y.val
}

task {
    x &lt;&lt; 10
}

task {
    y &lt;&lt; 5
}

println &quot;Result: ${z.val}&quot;

Try it in the Groovy Web Console

huangapple
  • 本文由 发表于 2023年7月3日 05:30:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定