以解决,总结一下就是添加此依赖到pom指定 kotlin coroutines 版本
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.7.1</version>
</dependency>
以解决,总结一下就是添加此依赖到pom指定 kotlin coroutines 版本
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.7.1</version>
</dependency>
@cssxsh
抱歉我不是很了解 kotlin 的依赖,我尝试下面的指定,好像仍然依赖打架,
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.7.1</version>
</dependency>
错误信息仍然是
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
net.mamoe.mirai.internal.deps.io.ktor.client.utils.CoroutineDispatcherUtilsKt.clientDispatcher(CoroutineDispatcherUtils.kt:22)
The following method did not exist:
'kotlinx.coroutines.CoroutineDispatcher kotlinx.coroutines.CoroutineDispatcher.limitedParallelism(int)'
The method's class, kotlinx.coroutines.CoroutineDispatcher, is available from the following locations:
jar:file:/home/spring/.m2/repository/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1.jar!/kotlinx/coroutines/CoroutineDispatcher.class
The class hierarchy was loaded from the following locations:
kotlinx.coroutines.CoroutineDispatcher: file:/home/spring/.m2/repository/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1.jar
kotlin.coroutines.AbstractCoroutineContextElement: file:/home/spring/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.8.0/kotlin-stdlib-1.8.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of kotlinx.coroutines.CoroutineDispatcher
看了看依赖树,似乎依赖的是1.5.21?
[INFO] +- net.mamoe:mirai-core-jvm:jar:2.14.0:compile
[INFO] | +- net.mamoe:mirai-core-api-jvm:jar:2.14.0:compile
[INFO] | | +- org.jetbrains.kotlin:kotlin-reflect:jar:1.5.21:compile
[INFO] | | \- net.mamoe:mirai-console-compiler-annotations-jvm:jar:2.14.0:runtime
[INFO] | +- org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:jar:1.3.3:compile
[INFO] | +- org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:jar:1.3.3:compile
[INFO] | +- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:jar:1.5.1:compile
[INFO] | +- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.5.21:compile
[INFO] | +- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:jar:1.5.1:compile
[INFO] | +- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.5.21:compile
[INFO] | | \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.5.21:compile
[INFO] | +- org.bouncycastle:bcprov-jdk15on:jar:1.64:compile
[INFO] | +- me.him188:kotlin-jvm-blocking-bridge-runtime-jvm:jar:2.1.0-170.1:runtime
[INFO] | +- me.him188:kotlin-dynamic-delegation-jvm:jar:0.3.0-170.1:runtime
[INFO] | +- net.mamoe:mirai-core-utils-jvm:jar:2.14.0:runtime
[INFO] | +- org.jetbrains.kotlinx:kotlinx-serialization-protobuf-jvm:jar:1.3.3:runtime
[INFO] | +- org.jetbrains.kotlinx:atomicfu-jvm:jar:0.18.3:runtime
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
[INFO] | \- io.netty:netty-handler:jar:4.1.66.Final:runtime
[INFO] | +- io.netty:netty-common:jar:4.1.66.Final:runtime
[INFO] | +- io.netty:netty-resolver:jar:4.1.66.Final:runtime
[INFO] | +- io.netty:netty-buffer:jar:4.1.66.Final:runtime
[INFO] | +- io.netty:netty-transport:jar:4.1.66.Final:runtime
[INFO] | \- io.netty:netty-codec:jar:4.1.66.Final:runtime
[INFO] +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.8.0:compile
[INFO] | \- org.jetbrains:annotations:jar:13.0:compile
[INFO] \- org.jetbrains.kotlinx:kotlinx-coroutines-core:jar:1.7.1:compile
尴尬,现在排查发现,2.13.0之后的任何版本都会出现 kotlin 冲突,但是不能改标题了,okhttp 似乎在 2.13.0-RC2 修好了
MessageChain.serializeToJsonString(MessageChain message)
或者 MessageChain.serializeToString(MessageChain message)
反序列化使用对应的 MessageChain.deserializeFromXXX()
补充: 更新至 2.14.x 时会提示 kotlin 冲突
已知依赖 kotlin 的库包括 skija, mirai-core-jvm
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
net.mamoe.mirai.internal.deps.io.ktor.client.utils.CoroutineDispatcherUtilsKt.clientDispatcher(CoroutineDispatcherUtils.kt:22)
The following method did not exist:
'kotlinx.coroutines.CoroutineDispatcher kotlinx.coroutines.CoroutineDispatcher.limitedParallelism(int)'
The method's class, kotlinx.coroutines.CoroutineDispatcher, is available from the following locations:
jar:file:/home/spring/.m2/repository/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1.jar!/kotlinx/coroutines/CoroutineDispatcher.class
The class hierarchy was loaded from the following locations:
kotlinx.coroutines.CoroutineDispatcher: file:/home/spring/.m2/repository/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1.jar
kotlin.coroutines.AbstractCoroutineContextElement: file:/home/spring/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.5.10/kotlin-stdlib-1.5.10.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of kotlinx.coroutines.CoroutineDispatcher
进程已结束,退出代码1
由于屎山较高,没法排除其他库依赖的 Kotlin ,所以目前没法排查,不过项目完整的pom如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.now</groupId>
<artifactId>nowbot</artifactId>
<version>linux</version>
<name>nowbot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<skipTests>true</skipTests>
<mirai.version>2.14.0</mirai.version>
<run.os>linux</run.os>
<flexmark.version>0.26.4</flexmark.version>
</properties>
<repositories>
<repository>
<id>space-maven</id>
<name>skija</name>
<url>https://packages.jetbrains.team/maven/p/skija/maven/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>yoava</id>
<name>AOL yoava</name>
<url>http://yoava.artifactoryonline.com/yoava/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-log4j2</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-toml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-jvm</artifactId>
<version>${mirai.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.skija</groupId>
<artifactId>skija-${run.os}</artifactId>
<version>0.93.1</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<!-- sqlite-->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.github.gwenn</groupId>
<artifactId>sqlite-dialect</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-core</artifactId>
<version>1.28</version>
</dependency>
<dependency>
<groupId>com.kennycason</groupId>
<artifactId>kumo-tokenizers</artifactId>
<version>1.28</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.4.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-all</artifactId>
<version>0.64.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration><fork>false</fork></configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
注册bot bean的代码
@Bean
public Bot bot(){
//创建bot配置类
BotConfiguration botConfiguration = new BotConfiguration();
//设置配置
botConfiguration.setCacheDir(new File(BOT_PATH)); //BOT_PATH 为定义好的常量
botConfiguration.setHeartbeatStrategy(BotConfiguration.HeartbeatStrategy.REGISTER);
botConfiguration.setProtocol(BotConfiguration.MiraiProtocol.IPAD);
botConfiguration.setWorkingDir(new File(BOT_PATH));
File logdir = new File(BOT_PATH+"log");
if (!logdir.isDirectory()) logdir.mkdirs();
botConfiguration.redirectBotLogToDirectory(logdir);
botConfiguration.redirectNetworkLogToDirectory(logdir);
botConfiguration.fileBasedDeviceInfo();
botConfiguration.enableContactCache();
botConfiguration.getContactListCache().setSaveIntervalMillis(60000*30);
//配置完成,注册bot
Bot bot = BotFactory.INSTANCE.newBot(QQ,PASSWORD,botConfiguration); //QQ,PASSWORD也是定义好的常量
//注册监听 messageListener需要继承SimpleListenerHost类
bot.getEventChannel().parentScope(messageListener).registerListenerHost(messageListener);
return bot;
}
在2.12.3包括之前的任意版本都可以正常工作,但是更新至2.13.x之后的任何版本,都会出现
Caused by: java.util.ServiceConfigurationError: net.mamoe.mirai.IMirai: Provider net.mamoe.mirai.internal.MiraiImpl could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586) ~[na:na]
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:813) ~[na:na]
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729) ~[na:na]
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403) ~[na:na]
at kotlin.collections.CollectionsKt___CollectionsKt.firstOrNull(_Collections.kt:270) ~[kotlin-stdlib-1.5.10.jar:1.5.10-release-890 (1.5.10)]
at net.mamoe.mirai.utils.ServicesKt.loadService(Services.kt:18) ~[mirai-core-utils-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.Mirai.findMiraiInstance(IMirai.kt:357) ~[mirai-core-api-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai._MiraiInstance.get(IMirai.kt:348) ~[mirai-core-api-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.Mirai.getInstance(IMirai.kt:39) ~[mirai-core-api-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.internal.message.MessageSerializersImpl.getSerializersModule(MessageSerializersImpl.kt:65) ~[mirai-core-api-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.internal.message.MessageSerializersImpl.registerSerializers(MessageSerializersImpl.kt:76) ~[mirai-core-api-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.message.MessageSerializers$INSTANCE.registerSerializers(MessageSerializers.kt) ~[mirai-core-api-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.internal.message.protocol.MessageProtocolFacade.<clinit>(MessageProtocolFacade.kt:165) ~[mirai-core-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.internal.MiraiImplKt._MiraiImpl_static_init(MiraiImpl.kt:25) ~[mirai-core-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.internal.MiraiImpl.<clinit>(MiraiImpl.kt:87) ~[mirai-core-jvm-2.13.0.jar:2.13.0]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ~[na:na]
... 53 common frames omitted
Caused by: java.lang.NoClassDefFoundError: net/mamoe/mirai/internal/deps/io/ktor/client/engine/okhttp/OkHttp
at net.mamoe.mirai.internal.MiraiImplKt.createDefaultHttpClient(MiraiImpl.kt:29) ~[mirai-core-jvm-2.13.0.jar:2.13.0]
at net.mamoe.mirai.internal.MiraiImpl.<init>(MiraiImpl.kt:97) ~[mirai-core-jvm-2.13.0.jar:2.13.0]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ~[na:na]
... 72 common frames omitted
Caused by: java.lang.ClassNotFoundException: net.mamoe.mirai.internal.deps.io.ktor.client.engine.okhttp.OkHttp
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
... 80 common frames omitted
进程已结束,退出代码1
我添加了 okhttp 的依赖项也无法解决 pom文件:
<properties>
<mirai.version>2.13.0</mirai.version>
</properties>
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-jvm</artifactId>
<version>${mirai.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.8.1</version>
<scope>compile</scope>
</dependency>
我不知道如何解决 Okhttp 的依赖冲突(如果问题是这个的话,因为看包名net/mamoe/mirai/internal/deps/io/ktor/client/engine/okhttp/OkHttp
似乎是在mirai自己内部实现了,不应该外部管理?)
@rainchan 在 有没有只针对于mirai的设置代理方法(http/socket5代理),非全局代理 中说:
jvm设置代理
jvm设置代理可否只针对mirai发送的请求进行代理,有的话,求搜索关键词
太长可以直接看最底下
最近一段时间发送图片巨慢无比(恒定135s的延迟,无论图片大小),定位到是位于
ExternalResource.uploadAsImage(ExternalResource.create(byte[]), contact)
方法造成的
目前bot发送文字消息都是秒回复,但是图片发送延迟过大
切换登录协议及心跳协议均无效
而且多次测试,发送一张图之后再次发送相同的图片是很快的,但是每次发送新图片就会有非常稳定的延迟,约130-137秒,无论是3M大小的图片文件还是20k的图片,都是130秒+,暂时不怀疑服务器带宽 (带宽10mbps,发几百Kb的图片不至于两分钟起步)
我推测是因为服务器在国外所以可能经过某种审查,或者腾讯服务器转发国内图片进行处理,因为本地测试图片秒发,服务器上的bot切换账号,登录协议心跳协议均无法解决
准备尝试一下回国代理是否能解决,但是目前查到的都是对系统或者jvm代理
bot在运行的时候会访问国外的数据源获取数据,所以不想使用全局代理,有没有单独让bot走代理的方法呢
请问关于2.8.0版本的AbsoluteFileFolder文件操作java如何使用,以及私聊文件的事件或者文件发送/接受事件如何监听,似乎MessageEvent无法监听私聊文件发送