1

我是 Gradle 的新手,我不知道该怎么做。
这是关于如何通过 Gradle 安装 Quasar 的 Quasar 文档:Quasar Docs
页面中还有一个模板项目:Template Gradle Project
最后这是我的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 {
compile '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
}
task runQuasar {
    jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"


}
run.dependsOn runQuasar

我得到这个错误:

FAILURE: Build failed with an exception.

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

* What went wrong:
A problem occurred evaluating root project 'TGAdminsBot'.
> java.util.NoSuchElementException (no error message)

所以我该怎么做?我再次很抱歉问这个问题,但我是 Gradle 的新手,在发布这个问题之前我用谷歌搜索了很多。谢谢

4

2 回答 2

2

出现了三个问题。

  1. configurations之前定义的dependencies
  2. 需要两行dependencies


    编译 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
    类星体 'co.paralleluniverse:quasar-core:0.7.4:jdk8'


  3. 缺少此块:


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


最后这是最终的build.gradle

group 'TGAdminsBot'
version '0.1'

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8

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

}
configurations {
    quasar
}

dependencies {
    compile 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
    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'

}


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

    main = 'com.sunova.bot.Launcher'
    classpath = sourceSets.main.runtimeClasspath
}
于 2016-05-06T14:43:28.263 回答
1

我认为您的问题主要在于定义runQuasar哪个不是运行任务,因此没有jvmArgs属性,但是,如果您由于其他我不知道的原因不需要它,只需在 Gradle 模板项目中执行(代理配置)而不是定义runQuasar和声明run依赖于它:

applicationDefaultJvmArgs = [
    "-javaagent:${configurations.quasar.singleFile}" // =v, =d
]

如果你需要一个单独的runQuasar我认为你需要将它声明为一个JavaExec任务(看看这里)。

于 2016-05-06T06:30:50.170 回答