Kaktushose / jda-commands

A declarative, annotation driven command library for JDA
https://github.com/Kaktushose/jda-commands/wiki
Apache License 2.0
66 stars 11 forks source link

Doesn't find Commands when packaged #18

Closed DiamondCrystl closed 3 years ago

DiamondCrystl commented 3 years ago

When I package my Bot to a .jar file it doesn't find any Commands anymore. The Program itself and the help Command works without problems, it's just the custom Commands that don't work.

Kaktushose commented 3 years ago

interesting, I'll investigate it

Kaktushose commented 3 years ago

Okay, I wasn't able to reproduce this behaviour. However the i18n feature of this framework had some bugs resulting in npe's. But they should be fixed with the latest commit on dev branch. If the problem persists even after upgrading to the latest version, it would be nice if you could provide some more information, like your maven/gradle setup or log files.

DiamondCrystl commented 3 years ago

Unfortunately, I still couldn't get it to work even on the last commit of the dev branch. Here's some info about my Setup: I package everything with the Shadow plugin. My IDE is IntelliJ and my Gradle version is my build.gradle file looks like this

plugins {
    id 'java'
    id 'maven-publish'
    id 'idea'
    id 'com.github.johnrengelman.shadow' version '6.1.0'
}

compileJava.options.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://jitpack.io')
    }

    maven {
        url = uri('https://jcenter.bintray.com')
    }

    maven {
        url = uri('https://repo.maven.apache.org/maven2/')
    }

    maven {
        url  "https://dl.bintray.com/johnrengelman/gradle-plugins"
    }
}

dependencies {

    implementation 'ai.djl.pytorch:pytorch-engine:0.10.0'
    implementation 'ai.djl.pytorch:pytorch-native-auto:1.7.1'

    implementation ('ai.djl.onnxruntime:onnxruntime-engine:0.10.0'){
        exclude group: "com.microsoft.onnxruntime", module: "onnxruntime"
    }
    implementation "com.microsoft.onnxruntime:onnxruntime:1.7.0"

    constraints {
        implementation 'org.apache.commons:commons-text:1.9'
    }

    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'org.json:json:20160212'
    implementation 'com.google.api-client:google-api-client:1.31.1'
    implementation 'com.google.apis:google-api-services-oauth2:v2-rev20200213-1.31.0'
    implementation 'com.google.apis:google-api-services-youtube:v3-rev20201214-1.31.0'
    implementation 'com.google.oauth-client:google-oauth-client-jetty:1.31.0'
    implementation 'com.sedmelluq:lavaplayer:1.3.73'
    implementation 'com.github.markozajc:akiwrapper:1.5'
    implementation 'com.github.ben-manes.caffeine:caffeine:2.8.8'
    implementation 'com.jagrosh:jda-utilities:3.0.5'
    implementation 'net.dv8tion:JDA:4.2.0_223'
//    implementation 'com.github.Kaktushose:jda-commands:1.1.1'
    implementation 'com.github.Kaktushose:reactionwaiter:2.0.0'
    implementation 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
    implementation 'com.github.Kaktushose:jda-commands:94c6a6ade5'

}

group = 'org.Diamond'
version = '1.0-SNAPSHOT'
description = 'DiscordBot'
java.sourceCompatibility = JavaVersion.VERSION_15

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

jar {
    manifest {
        attributes(
                'Main-Class': "test"
        )
    }
}
Kaktushose commented 3 years ago

could you also provide a debug level log file / console output?

oleggtro commented 3 years ago

"works on my machine"

DiamondCrystl commented 3 years ago

Ah yes, here's the console output

01:52:15.357 JDA RateLimit-Worker 1                        Requester       DEBUG  Received response with following cf-rays: [6395baea4e9acbb8-VIE]
01:52:15.658 JDA RateLimit-Worker 2                        Requester       DEBUG  Received response with following cf-rays: [6395baebaf43cbb8-VIE]
01:52:15.665 main                                          JDA             INFO   Login Successful!
01:52:15.691 main                                          SessionControll DEBUG  Creating new worker handle for shard pool 0
01:52:15.692 main                                          SessionControll DEBUG  Running worker
01:52:15.693 ConcurrentSessionController-Worker            SessionControll DEBUG  Running connect node for shard Shard [0 / 1]
01:52:15.764 main                                          TrustManagerBui DEBUG  Certificate list /certificates/extended.txt not present in classpath.
Utils.Other.SaveClass@5f20155b
01:52:15.806 main                                          CommandDispatch INFO   Starting JDA-Commands...
01:52:15.813 main                                          CommandRegistry DEBUG  Indexing commands...
01:52:15.813 main                                          CommandRegistry DEBUG  No package specified. Going to scan whole project...
01:52:15.845 main                                          Reflections     WARN   given scan urls are empty. set urls in the configuration
01:52:15.858 main                                          CommandRegistry INFO   Command indexing done! Indexed a total of 0 commands!
01:52:15.858 main                                          CommandDispatch INFO   Finished loading!
[]
{}
01:52:16.022 JDA MainWS-WriteThread                        WebSocketClient INFO   Connected to WebSocket
01:52:16.022 JDA MainWS-WriteThread                        WebSocketClient DEBUG  Connected with gateway intents: 11011110001011
01:52:16.022 JDA MainWS-WriteThread                        WebSocketClient DEBUG  Sending Identify-packet...
01:52:16.028 JDA MainWS-ReadThread                         WebSocketClient DEBUG  Got HELLO packet (OP 10). Initializing keep-alive.
01:52:16.304 JDA MainWS-ReadThread                         GuildSetupContr DEBUG  Setting incomplete count to 3
01:52:16.305 JDA MainWS-ReadThread                         GuildSetupContr DEBUG  Starting 75 second timeout for 3 guilds
01:52:16.357 JDA MainWS-ReadThread                         GuildSetupContr DEBUG  Finished setup for guild 770047224234901555 firing cached events 0
01:52:16.374 JDA MainWS-ReadThread                         GuildSetupContr DEBUG  Finished setup for guild 792601042566643723 firing cached events 0
01:52:16.381 JDA MainWS-ReadThread                         JDA             INFO   Finished Loading!
01:52:16.383 JDA MainWS-ReadThread                         GuildSetupContr DEBUG  Finished setup for guild 811578217013968907 firing cached events 0
Kaktushose commented 3 years ago
01:52:15.845 main                                          Reflections     WARN   given scan urls are empty. set urls in the configuration
01:52:15.858 main                                          CommandRegistry INFO   Command indexing done! Indexed a total of 0 commands!

That says it all. Reflections isn't scanning anything, thus no commands are indexed. This is pretty weird because I'm still not able to reproduce the bug, but I am using maven, so maybe @cloudybyte can try to reproduce it with gradle. I believe this is a bug in the org.reflections library, but all I can find about it, is this issue. Unfortunately the project is apparently no longer maintained.

A potential fix could be to specify a package aka URL to scan by using the setCommandPackage method. (Introduced in v1.1.1)

If you want, you can send me your whole code base, so I can investigate this problem further.

DiamondCrystl commented 3 years ago

Okay, so, if I use the setCommandPackage method it works, thank you very much! Do you still want to investigate it? And if so, should I just send the code in here via a zip file?

Kaktushose commented 3 years ago

yes I'd like to. You can also send it to me via discord. Kaktushose#0436

DiamondCrystl commented 3 years ago

I sent you a friend request, will send the zip after you accepted it

Kaktushose commented 3 years ago

I'm unable to locate the origin of this bug, but I believe that it's a bug within org.relections Use the setCommandPackage method to avoid it

oleggtro commented 3 years ago

pls close @Kaktushose

Kaktushose commented 3 years ago

I think that I was able to resolve this issue. This issue will be fixed in #32

Kaktushose commented 2 years ago

Version v.2.0.0 got released and thus the issue has been resolved