How to configure Quasar in Gradle

I’m new to Gradle and I don’t know what to do.
Here is Quasar docs about how to install Quasar through Gradle: Quasar Docs
There is also a template project in the page: Template Gradle Project
Update:
This is my new build.gradle:
group 'TGAdminsBot’
version ‘0.1’

apply plugin: 'java'
apply plugin: 'idea'
//apply plugin: 'application'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}
//mainClassName = "Launcher"
idea {
    module
            {
                downloadJavadoc = true
                downloadSources = true
            }

}
dependencies {
    quasar 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'

    compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
    //compile 'com.github.User:Repo:Tag'
    //compile 'com.mashape.unirest:unirest-java:1.4.9'
    compile 'co.paralleluniverse:comsat-httpclient:0.7.0'
    compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
    testCompile group: 'junit', name: 'junit', version: '4.11'

}
configurations {
    quasar
}
tasks.withType(JavaExec)
        {
            jvmArgs "-javaagent:${configurations.quasar.singleFile}"
        }
task run(type: JavaExec) {

//    jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
    main = 'com.sunova.bot.Launcher'
    classpath = sourceSets.main.runtimeClasspath

}
run.delepndsOn runQuasar

And this is new Exception:
9:09:36 PM: Executing external task ‘run’…

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Sobhan\Documents\IntelliJIDEAProjects\TGAdminsBot\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating root project 'TGAdminsBot'.
> Could not find method quasar() for arguments [co.paralleluniverse:quasar-core:0.7.4:jdk8] on root project 'TGAdminsBot'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

What is wrong this time?

I assuming you are writing some tests, rather than just run a Jar, so by a quick look I think you need to change your build.gradle as follows:

Fix the dependencies block

dependencies {
  quasar 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
  compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
  compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
  compile 'co.paralleluniverse:comsat-httpclient:0.7.0'
  compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
  testCompile group: 'junit', name: 'junit', version: '4.11'
}

Now remove the runQuasar task and set the test task to know about quasar

test {
  jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
}

If you are not testing, but are running a Java task instead you’ll need to read up on JavaExec in the documentation.

1 Like

Thanks you saved me. But if I want to run the project with this “Quasar” configuration, should I write a new run task rather than using application plugin?
Thanks again

As run (from the application plugin) is already of type JavaExec, I believe all you need to do is

run {
  jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
}

HTH

1 Like

There were three problems.

  • First one was configurations were defined before dependencies.

  • Second was two lines were needed in dependencies:

    compile 'co.paralleluniverse:quasar-core:0.7.4:jdk8’
    quasar ‘co.paralleluniverse:quasar-core:0.7.4:jdk8’

  • Third one was lack of this block:


tasks.withType(JavaExec){
            jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
        }

Both Schalk Cronjé’s comments were true. However run requires classpath and main class declaration. So I preferred using application plugin and tasks.withType(JavaExec) together.

1 Like

Hey! Using withType in this context was a cool idea.

1 Like