Gradle with GPARS

Answered

hi,

Really, really new to gradle. i've the following build.gradle and i want to use gpars. in intellij i'm getting the following error. can you help please.

 

* What went wrong:
A problem occurred evaluating root project 'example.project'.
> Could not get unknown property 'GParsPool' for root project 'example.project' of type org.gradle.api.Project.

version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
//add repositories for optional dependencies
// maven{url 'http://repository.jboss.org/maven2/'}
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.codehaus.gpars', name: 'gpars', version: '1.2.1'
}

def sendEmails(numbers) {


GParsPool.withPool {
numbers.eachParallel { number ->
def wait = (long) new Random().nextDouble() * 1000
println "in closure " + number
this.sleep wait
}
}

}

task showDate{

sendEmails([1,2,3])
}
0
4 comments

You are missing a classpath dependency and an import:

import groovyx.gpars.GParsPool

dependencies {
  classpath "org.codehaus.gpars:gpars:1.2.1"
}
0
Avatar
Permanently deleted user

Hi Serge.

I added the import and classpath. now i receive the following error.

 

* What went wrong:
Could not compile build file '/home/neo/IdeaProjects/example.project/build.gradle'.
> startup failed:
  build file '/home/neo/IdeaProjects/example.project/build.gradle': 2: unable to resolve class groovyx.gpars.GParsPool
   @ line 2, column 1.
     import groovyx.gpars.GParsPool

0

Google for the proper configuration, you may need to add classpath inside buildscript element. The issue has no relation to IntelliJ IDEA, you will have the same problem with the command line Gradle. If you can't find the solution, try asking at http://stackoverflow.com/.

0
Avatar
Permanently deleted user

Appears the important part is the is indeed the buildscript portion.

 

import groovyx.gpars.GParsPool

buildscript {
repositories {
mavenCentral()
}

dependencies {
classpath "org.codehaus.gpars:gpars:1.1.0"
}
}

version '1.0-SNAPSHOT'
apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile 'org.projectlombok:lombok:1.16.18'
testCompile "org.codehaus.groovy:groovy-all:2.1.0"
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'org.mockito:mockito-core:2.10.0'
}


def doNumbers(numbers) {
GParsPool.withPool {
numbers.eachParallel { number ->
def wait = (long) new Random().nextDouble() * 1000
println "in closure " + number
this.sleep wait
}
}
}

task runNumbers{
doLast {
doNumbers([1,2,3])
}
}
0

Please sign in to leave a comment.