Bootstrap options
1 2 3 4 5 6 7 |
gradle init --type pom gradle init --type java-application [--test-framework spock | testng] gradle init --type java-library [--test-framework spock | testng] gradle init --type scala-library gradle init --type groovy-library gradle init --type groovy-application gradle init --type basic |
Gradle Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# create app mkdir lidenlab-app && cd lidenlab-app # bootstrap java project gradle init --type java-application # build project (runs unit tests) ./gradlew build # check the test results build/reports/tests/test/index.html # list available Gradle tasks ./gradlew tasks # execute main ./gradlew run # delete app cd .. && rm -rf lidenlab-app |
Common Config (in progress)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
apply plugin: 'java' apply plugin: 'application' // specify Java version sourceCompatibility = 1.8 targetCompatibility = 1.8 // for gradle run mainClassName = "com.lidenlab.App" repositories { //mavenCentral() jcenter() } dependencies { compile "groupId:artifactId:version" testCompile group: 'junit', name: 'junit', version: '4.12' } |
Create runnable Jar file
Configure the Jar task of the Java plugin:
1 2 3 4 5 6 7 |
apply plugin: 'java' jar { manifest { attributes 'Main-Class': 'com.lidenlab.App' } } |
Force running subsequent tests
1 2 3 4 5 6 7 8 9 10 11 |
# use the rerun flag gradle test --rerun-tasks # clean the tests gradle cleanTest test # configure test to depend on cleanTest in build.gradle test { dependsOn 'cleanTest' //Your previous task details (if any) } |
Show StandardStreams from tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// show System.out.println and System.err.println test { testLogging { showStandardStreams = true // events method: // events 'STANDARD_OUT', 'STANDARD_ERROR' // events method with enum values: // events org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT, // org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR, // Or set events property: // events = ['STANDARD_OUT', 'STANDARD_ERROR'] } } |
See: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.logging.TestLoggingContainer.html
References and Resources
- https://docs.gradle.org/current/userguide/userguide.html
- https://docs.gradle.org/current/userguide/gradle_command_line.html
- https://docs.gradle.org/current/userguide/build_init_plugin.html
- https://docs.gradle.org/current/userguide/application_plugin.html
- https://docs.gradle.org/current/userguide/java_plugin.html
- https://github.com/johnrengelman/shadow