Gradle - application

Run No arg main class
Java 
package examples;
public class TestMain {
    public static void main(String[] params) {
        System.out.println("hello");
    }
}
build.gradle
apply plugin: 'java'
apply plugin: 'application'
mainClassName= 'examples.TestMain'

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.12'
}
Run
$ gradle run

> Task :run
hello

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings


BUILD SUCCESSFUL in 952ms
3 actionable tasks: 3 executed

Run main class with hard code arg
Java
package examples;
public class TestMain {
    public static void main(String[] params) {
        System.out.println("hello " + params[0]);
    }
}
build.gradle
apply plugin: 'java'
apply plugin: 'application'
mainClassName= ‘examples.TestMain'

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.12'
}

run.args = ['abc']
Run
apply plugin: 'java'
apply plugin: 'application'
mainClassName= 'examples.TestMain'

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.12'
}

run.args = ['abc']

Run main class with command line arg
Java
package examples;
public class TestMain {
    public static void main(String[] params) {
        System.out.println("hello " + params[0]);
    }
}
build.gradle
apply plugin: 'java'
apply plugin: 'application'
mainClassName= 'examples.TestMain'


repositories {
    mavenCentral()
}


dependencies {
    testCompile 'junit:junit:4.12'
}
run.args = [project.args] //simply args can work as well
Run
$ gradle clean run -Pargs=ABC

> Task :run
hello ABC

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 760ms
4 actionable tasks: 4 executed







沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...