MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    Solved 为子项目配置mirai-core依赖时出现的问题

    开发交流
    3
    5
    809
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Under-estimate
      Under-estimate 摸鱼 last edited by

      项目结构如图所示:
      7bd533c0-939f-4a74-999c-e5afbd8cbcfe-image.png
      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执行后也没有效果。
      3406f33f-4904-4262-b360-15470300c16c-image.png
      尝试清除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

      几个月之前这样的配置是可以正常工作的,今天重新打开这个项目时发现出现了此问题

      1 Reply Last reply Reply Quote 0
      • Karlatemp
        Karlatemp last edited by

        正常开发请使用 mirai-core-api, core只需要运行时有

        1 Reply Last reply Reply Quote 0
        • RainChan
          RainChan 摸鱼 last edited by

          @Him188

          1 Reply Last reply Reply Quote 0
          • Karlatemp
            Karlatemp last edited by

            plugins {
              id 'kt.jvm'
            }
            
            1 Reply Last reply Reply Quote 0
            • Karlatemp
              Karlatemp last edited by

              正常开发请使用 mirai-core-api, core只需要运行时有

              1 Reply Last reply Reply Quote 0
              • Under-estimate
                Under-estimate 摸鱼 last edited by

                将子项目中

                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和实现的方式,成功解决问题。

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact