尝试 运行 vertx 应用程序时 Gradle 构建出现问题
Problem with Gradle build when trying to run vertx application
´´´
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'io.vertx.vertx-plugin' version '1.2.0'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
compile 'io.vertx:vertx-web-client:4.0.2'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
vertx {
mainVerticle = 'Reactx.BackendVerticle'
}
//Backend Verticle.java
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package Reactx;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
public class BackendVerticle extends AbstractVerticle {
@Override
public void start() {
// Create an HTTP server which simply returns "Hello World!" to each request.
// If a configuration is set it get the specified name
Router router = Router.router(vertx);
Route messageRoute = router.get("/api/message"); // (1)
messageRoute.handler(rc -> {
rc.response().end("Hello React from Vert.x!"); // (2)
});
router.get().handler(StaticHandler.create()); // (3)
vertx.createHttpServer()
.requestHandler(router)
.listen(8080);
}
// tag::main[]
public static void main(String[] args) {
Vertx vertx = Vertx.vertx(); // <1>
vertx.deployVerticle(new BackendVerticle()); // <2>
}
// end::main[]
}
´´´
当我尝试执行 gradle 运行 时,我收到 error::compileJava 任务失败。
如何解决?我不能尝试 kotlin,因为我有一些依赖性,我只想在 gradle.build 中执行它。我正在使用 gradle 版本 6.6 这也是由于项目的依赖性。
添加失败堆栈跟踪:
Gradle Version: 6.6
Java Home: C:\...\jdk1.8.0_282
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run
> Task :compileJava FAILED
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:8: error: package io.vertx.ext.web does not exist
import io.vertx.ext.web.Route;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:9: error: package io.vertx.ext.web does not exist
import io.vertx.ext.web.Router;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:10: error: package io.vertx.ext.web.handler does not exist
import io.vertx.ext.web.handler.StaticHandler;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:18: error: cannot find symbol
Router router = Router.router(vertx);
^
symbol: class Router
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:18: error: cannot find symbol
Router router = Router.router(vertx);
^
symbol: variable Router
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:19: error: cannot find symbol
Route messageRoute = router.get("/api/message"); // (1)
^
symbol: class Route
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:24: error: cannot find symbol
router.get().handler(StaticHandler.create()); // (3)
^
symbol: variable StaticHandler
location: class BackendVerticle
7 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 253ms
1 actionable task: 1 executed
您缺少 vertx-web
作为依赖项。
要修复您需要添加的编译问题:
dependencies {
//...
compile 'io.vertx:vertx-web:4.0.2'
}
´´´
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'io.vertx.vertx-plugin' version '1.2.0'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
compile 'io.vertx:vertx-web-client:4.0.2'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:29.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.13'
}
vertx {
mainVerticle = 'Reactx.BackendVerticle'
}
//Backend Verticle.java
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package Reactx;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
public class BackendVerticle extends AbstractVerticle {
@Override
public void start() {
// Create an HTTP server which simply returns "Hello World!" to each request.
// If a configuration is set it get the specified name
Router router = Router.router(vertx);
Route messageRoute = router.get("/api/message"); // (1)
messageRoute.handler(rc -> {
rc.response().end("Hello React from Vert.x!"); // (2)
});
router.get().handler(StaticHandler.create()); // (3)
vertx.createHttpServer()
.requestHandler(router)
.listen(8080);
}
// tag::main[]
public static void main(String[] args) {
Vertx vertx = Vertx.vertx(); // <1>
vertx.deployVerticle(new BackendVerticle()); // <2>
}
// end::main[]
}
´´´ 当我尝试执行 gradle 运行 时,我收到 error::compileJava 任务失败。 如何解决?我不能尝试 kotlin,因为我有一些依赖性,我只想在 gradle.build 中执行它。我正在使用 gradle 版本 6.6 这也是由于项目的依赖性。 添加失败堆栈跟踪:
Gradle Version: 6.6
Java Home: C:\...\jdk1.8.0_282
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: run
> Task :compileJava FAILED
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:8: error: package io.vertx.ext.web does not exist
import io.vertx.ext.web.Route;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:9: error: package io.vertx.ext.web does not exist
import io.vertx.ext.web.Router;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:10: error: package io.vertx.ext.web.handler does not exist
import io.vertx.ext.web.handler.StaticHandler;
^
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:18: error: cannot find symbol
Router router = Router.router(vertx);
^
symbol: class Router
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:18: error: cannot find symbol
Router router = Router.router(vertx);
^
symbol: variable Router
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:19: error: cannot find symbol
Route messageRoute = router.get("/api/message"); // (1)
^
symbol: class Route
location: class BackendVerticle
C:\CMWorkspaceUpdated\Reactx\src\main\java\Reactx\BackendVerticle.java:24: error: cannot find symbol
router.get().handler(StaticHandler.create()); // (3)
^
symbol: variable StaticHandler
location: class BackendVerticle
7 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 253ms
1 actionable task: 1 executed
您缺少 vertx-web
作为依赖项。
要修复您需要添加的编译问题:
dependencies {
//...
compile 'io.vertx:vertx-web:4.0.2'
}