java - 尝试运行 vertx 应用程序时出现 Gradle 构建问题
问题描述
'''
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 运行时,我收到一个错误::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'
}
推荐阅读
- dotnetnuke-7 - 尝试将其从 dnn7 移动到 dnn9 后 DNN 模块错误
- swift - Apple Vision – 是否可以从静态图像中获取相机位置?
- php - 如何在 PHPSpreadsheet 中获取自定义数字格式
- sql - 给定表中给定行中空值的百分比
- excel - 如何遍历列表并打印输出
- flutter - analysis_options.yaml 未找到包含的文件
- artificial-intelligence - 测绘和自主无人机
- php - 如何显示在一定范围内跳过的数字mysql
- java - Apache Flink - 如何加载包含日期数据的 csv 数据集?
- r - 基于 R 中的 Rehimann Sum 的 AUC