Gradle 实现编译和运行Java程序

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

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

// main函数所在路径
mainClassName = 'com.mind.God'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
}

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

God.java

package com.mind;

/**
 * Created by Lovell on 16/7/1.
 */

public class God {
    private String configPath = "../../";

    private static God god;
    public static God getInstance(){
        if (god == null) {
            god = new God();
        }
        return god;
    }

    public void setConfigPath(String configPath) {
        this.configPath = configPath;
    }

    public String getConfigPath() {
        return configPath;
    }


    public static void main(String[] args) {
        System.out.println("message Hello World.");
        System.out.println("God");
//        God.getInstance().setConfigPath(args[0]);
    }
}
运行:gradle -q run

你可能感兴趣的:(Java,Gradle)