如何在 Gradle 中配置 Quasar
How to configure Quasar in Gradle
我是 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 的新手,在发布这个问题之前我用谷歌搜索了很多。谢谢
我认为您的问题主要在于 runQuasar
的定义,它不是 运行 任务,因此没有 jvmArgs
属性 但是,如果您不这样做由于我不知道的其他原因不需要它,只需执行 as in the Gradle template project (agent configuration) 而不是定义 runQuasar
并声明 run
依赖于它:
applicationDefaultJvmArgs = [
"-javaagent:${configurations.quasar.singleFile}" // =v, =d
]
如果您需要单独的 runQuasar
,我认为您需要将其声明为 JavaExec
任务(查看 here)。
遇到了三个问题。
configurations
在 dependencies
. 之前定义
dependencies
需要两行:
编译'co.paralleluniverse:quasar-core:0.7.4:jdk8'
类星体 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
缺少此块:
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
}
我是 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 的新手,在发布这个问题之前我用谷歌搜索了很多。谢谢
我认为您的问题主要在于 runQuasar
的定义,它不是 运行 任务,因此没有 jvmArgs
属性 但是,如果您不这样做由于我不知道的其他原因不需要它,只需执行 as in the Gradle template project (agent configuration) 而不是定义 runQuasar
并声明 run
依赖于它:
applicationDefaultJvmArgs = [
"-javaagent:${configurations.quasar.singleFile}" // =v, =d
]
如果您需要单独的 runQuasar
,我认为您需要将其声明为 JavaExec
任务(查看 here)。
遇到了三个问题。
configurations
在dependencies
. 之前定义
dependencies
需要两行:
编译'co.paralleluniverse:quasar-core:0.7.4:jdk8'
类星体 'co.paralleluniverse:quasar-core:0.7.4:jdk8'缺少此块:
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
}