英文:
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 << x.val + y.val
}
task {
x << 10
}
task {
y << 5
}
println "Result: ${z.val}"
Try it in the Groovy Web Console
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论