已解决 为子项目配置mirai-core依赖时出现的问题
- 
					
					
					
					
 项目结构如图所示: 
  
 InformationPanel为主项目,依赖于子项目Dependency,两个项目都依赖于mirai-core
 主项目的build.gradle配置:plugins { id 'org.jetbrains.kotlin.jvm' version '1.4.32' id 'com.github.johnrengelman.shadow' version '5.2.0' } group = 'InformationPanel' version = '1.0.0' repositories { maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } maven { url 'https://mirrors.huaweicloud.com/repository/maven' } mavenCentral() jcenter() } dependencies { api('net.mamoe:mirai-core:+') implementation 'com.alibaba:fastjson:+' implementation 'com.github.oshi:oshi-core:+' implementation 'org.reflections:reflections:+' implementation project(':Dependency') }子项目的 build.gradle配置:plugins { id 'idea' id 'java' } //这两个插件不能写在plugins中,否则gradle import会报错 apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'com.github.johnrengelman.shadow' repositories { maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'https://mirrors.huaweicloud.com/repository/maven' } mavenCentral() } dependencies { api('net.mamoe:mirai-core:+') implementation 'com.alibaba:fastjson:1.2.75' implementation 'org.slf4j:slf4j-simple:2.0.0-alpha1' implementation 'org.reflections:reflections:0.9.12' testImplementation('org.junit.jupiter:junit-jupiter:5.5.2') }按照如上的配置,gradle import之后主项目的依赖配置正常,但子项目的classpath中缺少 mirai-core依赖项。IntelliJ IDEA提供的修复选项Add library 'Gradle: ...' to classpath执行后也没有效果。
  
 尝试清除IntelliJ IDEA的缓存后重新导入无效,无视错误直接编译会编译失败,提示子项目中找不到mirai中各种类的定义。
 若将子项目作为单独的项目打开,将build.gradle中的kotlin.jvm以及johnrengelman.shadow插件写在plugin中并带上版本号,则依赖配置可以正常工作。
 考虑到mirai配置项目依赖的文档中提到:注意,必须添加 Kotlin 插件才能正确获取 mirai 软件包。 可能是因为子项目中两个插件未写在plugin中,但若将其写在plugin中则会在gradle import时报错: Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.4.32'] > Plugin request for plugin already on the classpath must not include a version附加信息 
 IntelliJ IDEA 版本2020.1 Ultimate,已安装Mirai Console插件版本2.6.1
 mirai-core 版本(主项目)2.7-M1-dev-1几个月之前这样的配置是可以正常工作的,今天重新打开这个项目时发现出现了此问题 
- 
					
					
					
					
 正常开发请使用 mirai-core-api, core只需要运行时有 
- 
					
					
					
					
 
- 
					
					
					
					
 plugins { id 'kt.jvm' }
- 
					
					
					
					
 正常开发请使用 mirai-core-api, core只需要运行时有 
- 
					
					
					
					
 将子项目中 plugins { id 'idea' id 'java' } apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'com.github.johnrengelman.shadow'改为 plugins { id 'org.jetbrains.kotlin.jvm' id 'com.github.johnrengelman.shadow' id 'idea' id 'java' }更改之后没有作用。 尝试使用分离API和实现的方式,成功解决问题。 
