MiraiForum

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

    配置文件的注释打不出来

    开发交流
    2
    8
    523
    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.
    • D
      Danile0 last edited by

      如图所示

      4d443af4-12b0-4f3b-8e82-d5543a67cbf8-image.png

      两种注解都试了,而且还多一条横杠
      4fd7b4f2-4832-4ac8-994c-daf2a97382c0-image.png

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

        为什么不直接贴代码
        复现还得手打一遍你的代码

        D 1 Reply Last reply Reply Quote 0
        • D
          Danile0 @cssxsh last edited by

          @cssxsh 不好意思

          object A3BotConfig : ReadOnlyPluginConfig("A3BotConfig") {
          
              data class data(
                  @Comment("驱动")
                  val driver: String,
                  @Comment("数据库地址")
                  val url: String,
                  @Comment("数据库用户名")
                  val username: String,
                  @Comment("数据库密码")
                  val password: String,
              )
          
              @ValueDescription("数据库配置")
              val dataSource: MutableList<data> by value(mutableListOf(
                  data(
                      driver = "com.mysql.cj.jdbc.Driver",
                      url = "jdbc:mysql://localhost:3306/a3bot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai",
                      username = "root",
                      password = "admin"
                  )
              ))
          }
          
          1 Reply Last reply Reply Quote 0
          • cssxsh
            cssxsh last edited by

            没有复现

            你没有把 import 贴出来
            你这个 Comment 是 net.mamoe.yamlkt.Comment 吗

            D 1 Reply Last reply Reply Quote 0
            • D
              Danile0 @cssxsh last edited by

              @cssxsh 是的

              package com.ayang.plugin
              
              import kotlinx.serialization.Serializable
              import net.mamoe.mirai.console.data.ReadOnlyPluginConfig
              import net.mamoe.mirai.console.data.ValueDescription
              import net.mamoe.mirai.console.data.value
              import net.mamoe.yamlkt.Comment
              
              /**
               * @author JinLY
               * @description A3Bot配置文件
               * @date 2023-08-11 13:50:26
               */
              object A3BotConfig : ReadOnlyPluginConfig("A3BotConfig") {
              
                  @Serializable
                  data class data(
                      @Comment("驱动")
                      val driver: String,
                      @Comment("数据库地址")
                      val url: String,
                      @Comment("数据库用户名")
                      val username: String,
                      @Comment("数据库密码")
                      val password: String,
                  )
              
                  @ValueDescription("数据库配置")
                  val dataSource: MutableList<data> by value(mutableListOf(
                      data(
                          driver = "com.mysql.cj.jdbc.Driver",
                          url = "jdbc:mysql://localhost:3306/a3bot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai",
                          username = "root",
                          password = "admin"
                      )
                  ))
              }
              

              配置文件生成后:

              # 数据库配置
              dataSource: 
                - driver: com.mysql.cj.jdbc.Driver
                  url: 'jdbc:mysql://localhost:3306/a3bot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai'
                  username: root
                  password: admin
              
              1 Reply Last reply Reply Quote 0
              • cssxsh
                cssxsh last edited by

                把 build.gradle.kts
                关于 dependencies 的部分贴一下

                D 1 Reply Last reply Reply Quote 0
                • D
                  Danile0 @cssxsh last edited by

                  @cssxsh 我只是用kotlin写配置文件,其他都是java

                  build.gradle

                  plugins {
                      id 'org.jetbrains.kotlin.jvm' version '1.9.0'
                      id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
                      id 'net.mamoe.mirai-console' version '2.15.0'
                  }
                  
                  dependencies {
                      implementation 'org.ini4j:ini4j:0.5.4'
                      implementation 'com.alibaba.fastjson2:fastjson2:2.0.33'
                      implementation 'com.squareup.okhttp3:okhttp:4.11.0'
                      implementation 'net.mamoe.yamlkt:yamlkt-jvm:0.13.0'
                      implementation 'mysql:mysql-connector-java:8.0.33'
                      implementation 'cn.hutool:hutool-all:5.8.21'
                  
                  }
                  
                  group = 'com.ayang.plugin'
                  version = '1.1.5_bp'
                  
                  repositories {
                      maven { url 'https://maven.aliyun.com/repository/public' }
                      mavenCentral()
                  }
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • cssxsh
                    cssxsh last edited by cssxsh

                    implementation 'net.mamoe.yamlkt:yamlkt-jvm:0.13.0'
                    改成
                    compileOnly 'net.mamoe.yamlkt:yamlkt-jvm:0.13.0'

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