将机器人部署到Heroku的难度

时间:2020-11-06 10:45:13

标签: java maven gradle heroku discord

对此我完全陌生,需要帮助。

我已经完成了一些有关设置pom.xml文件和Procfile的事情,但是这是否有效以及文件层次结构是否正确对我来说还是个谜。

无论如何,当我部署到Heroku时,这是我收到的错误消息:

[ERROR] Failed to execute goal on project TokenBot1.0: Could not resolve dependencies for project org.example:TokenBot1.0:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: net.dv8tion:JDA:jar:4.2.0_214, com.jagrosh:jda-utilities:jar:3.0.4: Could not find artifact net.dv8tion:JDA:jar:4.2.0_214 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
       [ERROR] 
       [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
       [ERROR] Re-run Maven using the -X switch to enable full debug logging.
       [ERROR] 
       [ERROR] For more information about the errors and possible solutions, please read the following articles:
       [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
 !     ERROR: Failed to build app with Maven
       We're sorry this build is failing! If you can't find the issue in application code,
       please submit a ticket so we can help: https://help.heroku.com/
 !     Push rejected, failed to compile Java app.
 !     Push failed

我也不太了解Maven与Gradle,但是我认为我的项目最初是在使用Gradle,然后我遵循了一个指南尝试使用Maven进行安装,因为许多Heroku指南都希望使用Maven。

文件看起来像这样:

TokenBot 1.0

  • Procfile
  • build.gradle
  • .git
  • src
    • pom.xml
    • 主要
  • 构建
      • .jar文件

Procfile

worker: java -jar target/TokenBot 1.0-1.0-SNAPSHOT.jar

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>TokenBot1.0</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>net.dv8tion</groupId>
            <artifactId>JDA</artifactId>
            <version>4.2.0_214</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.jagrosh</groupId>
            <artifactId>jda-utilities</artifactId>
            <version>3.0.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

如果您需要了解其他信息,请告诉我。

在此先感谢任何可以提供帮助的人!

1 个答案:

答案 0 :(得分:-1)

我使用maven代替gradle重新制作了整个项目(只是挽救了代码),因为基本上每个教程我都可以找到使用过的maven。

接下来,我确保我仍然可以在本地运行我的bot(我必须对pom.xml文件做一些工作才能实现)

我发现唯一与我的实际情况相符的教程可以部署到heroku(减github),是俄语版本:https://www.youtube.com/watch?v=LRapMfUMe4s

精确地遵循了本教程之后,我唯一缺少的就是创建一个Procfile。完成后,转到heroku并启用应显示的dyno。

所以基本上:

  1. 使用maven而不是gradle创建一个新的项目文件
  2. 确保它在本地运行良好(都通过IntelliJ中的“运行”按钮并执行.jar文件)
  3. 按照上面的视频/旅程部署到heroku
  4. Procfile;确保在您的根文件夹中创建一个