How to run main method using Gradle from within IntelliJ IDEA?

Viewed 14118

Am new to IntelliJ IDEA (using 2017.1.3) and gradle...

Java file:

package com.example;

public class HelloGradle {

    public static void main(String[] args) {
        System.out.println("Hello Gradle!");
    }
}

build.gradle:

group 'com.example'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'application'

mainClassName = "HelloGradle"

sourceCompatibility = 1.8

repositories {
    maven {
        url("https://plugins.gradle.org/m2/")
    }
}

task(runMain, dependsOn: 'classes', type: JavaExec) {
    main = 'com.example.HelloGradle'
    classpath = sourceSets.main.runtimeClasspath
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

When I click on the run task inside the Gradle Projects window, I get the following:

enter image description here

How can I setup either Gradle or IntelliJ IDEA to print the content in the main method to IntelliJ IDEA's Console view?

Really don't understand why the Console view didn't pop up (from within IntelliJ IDEA and also why it doesn't show me what the error is)...

1 Answers
Related