我在使用 Gradle 时遇到问题,我的依赖项下载并包含在“外部库”中就好了,但我无法在 IntelliJ IDEA 中导入它的类。
请看以下图片:


这是我的 build.gradle:
buildscript {
ext.kotlin_version = '1.2.50'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'cf.dogo'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'maven'
mainClassName = "cf.dogo.core.boot.BootKt"
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven {url 'https://jitpack.io'}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-reflect"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile 'net.dv8tion:JDA:3.6.0_376'
compile 'org.mongodb:mongodb-driver:3.6.3'
compile 'com.github.NathanPB:DogoAPI:master-SNAPSHOT' //That one is the problematic dependency
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin …Run Code Online (Sandbox Code Playgroud) 有谁知道记录 Ktor 路线的正确方法是什么,旨在将其显示在 KDoc 上?例子:
route(DogoBot.data.API.ROUTE){
route("token"){
route("add"){
get("fromdiscord") { ... }
get { ... }
}
}
route("user"){
route("{id}") {
get { ... }
}
}
route("guild"){
route("{id}") {
get { ... }
}
}
}
Run Code Online (Sandbox Code Playgroud)
好吧,如果可能的话,我该怎么做?我应该在其中放入哪种类型的信息?如何在其他方面实现 Ktor 兼容性?(我还有一个自己制作的路由器用于其他用途)
我正在尝试使用 Java 脚本 API 评估 JVM 内的 Kotlin 代码。
try {
ScriptEngineManager().getEngineByExtension("kts").let {
it.eval("val f: (CommandContext.()->Any?) = {\n${this.args.joinToString(" ")}\n}; return f") as (CommandContext.()->Any?)
}().let { embed.setDescription(it.toString()) }
} catch (ex: Exception) {
embed.setColor(Color.RED)
embed.setDescription(StringWriter().also { ex.printStackTrace(PrintWriter(it)) }.toString())
}
Run Code Online (Sandbox Code Playgroud)
但是...ScriptEngineManager().getEngineByExtension("kts")返回给我一个空值。我已经添加了META-INF/services文件:
文件名:javax.script.ScriptEngineFactory
文件内容:org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory
根据 JetBrains 的说法,它应该可以工作:https://github.com/JetBrains/kotlin/tree/master/libraries/examples/kotlin-jsr223-local-example
我在构建使用 Java 9 功能的 Kotlin 项目时遇到了一些问题。我知道 kotlin 只允许生成 Java 8 字节码,但根据kotlinlang.org 的说法,它应该从 Kotlin 1.2 开始支持此功能:
Kotlin 标准库现在与 Java 9 模块系统完全兼容,该系统禁止拆分包(多个 jar 文件在同一包中声明类)。
好吧,让我解决我的问题:当我尝试执行 gradlebuild任务时遇到了这个问题:
04:29:27:正在执行任务“构建”...
任务 :compileKotlin FAILED e: 在模块图中找不到模块 java.base e: 在模块图中找不到模块 java.management
FAILURE:构建失败,出现异常。
出了什么问题:任务“:compileKotlin”执行失败。
编译错误。查看日志了解更多详情
尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。
在https://help.gradle.org获取更多帮助
BUILD FAILED in 0s 1 个可操作的任务:1 个执行编译错误。有关更多详细信息,请参阅日志 04:29:28:任务执行已完成“构建”。
我在谷歌上搜索了那个错误,发现这个主题有一个人有同样的问题,他说他通过针对大于 8 的 JDK 来修复它,但我已经使用 JDK 11 作为项目 SDK 和sourceCompatibility.
我会在这里留下 build.gradle 和项目结构的一些重要部分给你们检查。
构建.gradle
buildscript …Run Code Online (Sandbox Code Playgroud) 我一直在研究 Haskell 并且我成功地制作了一个算法来分解纸币中的给定货币价值,它需要对这个价值求和。可以在此处找到更好的解释(以及挑战本身)。
import Text.Printf
import Data.List
import Data.Ord
filterNearest :: Int->(Int->Bool)
filterNearest a = (\x -> (max a x) <= a)
findNearest :: Int->[Int]->Int
findNearest x possibilities = last $filter (filterNearest x) possibilities
decomposeOnce :: Int->[Int]->[Int]->[Int]
decomposeOnce x list possibilities = [findNearest x possibilities] ++ list
decomposeRecursive :: Int->[Int]->[Int]->[Int]
decomposeRecursive x list possibilities = if x /= 0
then
let decomposed = decomposeOnce x list possibilities
in decomposeRecursive (x - decomposed!!0) decomposed possibilities
else list
countGroup :: …Run Code Online (Sandbox Code Playgroud) kotlin ×4
gradle ×2
coin-change ×1
dependencies ×1
eval ×1
haskell ×1
import ×1
java ×1
java-module ×1
jvm ×1
kdoc ×1
ktor ×1
meta-inf ×1