IntelliJ无法为类型为org.gradle.api.Project的根项目'Blue Bot'设置未知属性'mainClassName'

时间:2019-11-20 23:27:51

标签: gradle

我正在按照教程制作基本的Discord Bot(https://medium.com/discord-bots/making-a-basic-discord-bot-with-java-834949008c2b),但出现错误,无法为org类型的根项目'Blue Bot'设置未知属性'mainClassName'。 gradle.api.Project ,我不知道如何解决。这是我的 build.grade 代码

plugins {
    id 'java'
}
mainClassName = "Main"
group 'BlueBot'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'net.dv8tion:JDA:4.0.0_62'
}

这是我的 Main.java 代码

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import javax.security.auth.login.LoginException;


public class Main extends ListenerAdapter {
    public static void main(String[] args) throws LoginException {
        JDABuilder builder = new JDABuilder(AccountType.BOT);
        String token = "enter token here";
        builder.setToken(token);
        builder.addEventListeners(new Main());
        builder.build();
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        System.out.println("We received a message from " +
                event.getAuthor().getName() + ": " +
                event.getMessage().getContentDisplay()
        );

        if (event.getMessage().getContentRaw().equals("I am lonely")) {
            event.getChannel().sendMessage("Who isn't?").queue();
        }
    }
}

让我知道是否需要更多信息。

1 个答案:

答案 0 :(得分:1)

您需要应用应用插件:

plugins {
    id 'application'
}