Skip to content

Commit 9caf73c

Browse files
abirkhan04pedja4
authored andcommitted
Gradle tutorial project : (eugenp#2922)
* Gradle tutorial project : 1. A multi-project build 2. Inclusive all required tasks and dependency example. * Gradle tutorial is shifted to gradle folder
1 parent 9f49798 commit 9caf73c

File tree

29 files changed

+407
-53
lines changed

29 files changed

+407
-53
lines changed

gradle/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.gradle/

gradle/.travis.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# More details on how to configure the Travis build
2+
# https://docs.travis-ci.com/user/customizing-the-build/
3+
4+
# Speed up build with travis caches
5+
cache:
6+
directories:
7+
- $HOME/.gradle/caches/
8+
- $HOME/.gradle/wrapper/
9+
10+
language: java
11+
12+
jdk:
13+
- oraclejdk8
14+
15+
#Skipping install step to avoid having Travis run arbitrary './gradlew assemble' task
16+
# https://docs.travis-ci.com/user/customizing-the-build/#Skipping-the-Installation-Step
17+
install:
18+
- true
19+
20+
#Don't build tags
21+
branches:
22+
except:
23+
- /^v\d/
24+
25+
#Build and perform release (if needed)
26+
script:
27+
- ./gradlew build -s && ./gradlew ciPerformRelease

gradle/build.gradle

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
apply plugin: 'java'
2-
apply plugin: 'maven'
1+
allprojects {
2+
repositories {
3+
jcenter()
4+
}
5+
}
6+
7+
8+
subprojects {
39

4-
repositories{
5-
mavenCentral()
10+
version = '1.0'
611
}
712

8-
dependencies{
9-
compile 'org.springframework:spring-context:4.3.5.RELEASE'
10-
}
13+
apply plugin: 'eclipse'
14+
15+
println 'This will be executed during the configuration phase.'
16+
17+
task configured {
18+
println 'This will also be executed during the configuration phase.'
19+
}
1120

12-
task hello {
13-
println "this Baeldung's tutorial is ${awesomeness}"
21+
task execFirstTest {
22+
doLast {
23+
println 'This will be executed during the execution phase.'
24+
}
1425
}
1526

16-
uploadArchives {
17-
repositories {
18-
mavenDeployer {
19-
repository(url: 'http://yourmavenrepo/repository') {
20-
authentication(userName: 'user', password: 'password');
21-
}
22-
23-
}
24-
}
27+
task execSecondTest {
28+
doFirst {
29+
println 'This will be executed first during the execution phase.'
30+
}
31+
doLast {
32+
println 'This will be executed last during the execution phase.'
33+
}
34+
println 'This will be executed during the configuration phase as well.'
2535
}

gradle/gradle.properties

-3
This file was deleted.

gradle/gradle/shipkit.gradle

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//This default Shipkit configuration file was created automatically and is intended to be checked-in.
2+
//Default configuration is sufficient for local testing and trying out Shipkit.
3+
//To leverage Shipkit fully, please fix the TODO items, refer to our Getting Started Guide for help:
4+
//
5+
// https://github.com/mockito/shipkit/blob/master/docs/getting-started.md
6+
//
7+
shipkit {
8+
//TODO is the repository correct?
9+
gitHub.repository = "unspecified-user/unspecified-repo"
10+
11+
//TODO generate and use your own read-only GitHub personal access token
12+
gitHub.readOnlyAuthToken = "76826c9ec886612f504d12fd4268b16721c4f85d"
13+
14+
//TODO generate GitHub write token, and ensure your Travis CI has this env variable exported
15+
gitHub.writeAuthToken = System.getenv("GH_WRITE_TOKEN")
16+
}
17+
18+
allprojects {
19+
plugins.withId("com.jfrog.bintray") {
20+
21+
//Bintray configuration is handled by JFrog Bintray Gradle Plugin
22+
//For reference see the official documentation: https://github.com/bintray/gradle-bintray-plugin
23+
bintray {
24+
25+
//TODO sign up for free open source account with https://bintray.com, then look up your API key on your profile page in Bintray
26+
key = '7ea297848ca948adb7d3ee92a83292112d7ae989'
27+
//TODO don't check in the key, remove above line and use env variable exported on CI:
28+
//key = System.getenv("BINTRAY_API_KEY")
29+
30+
pkg {
31+
//TODO configure Bintray settings per your project (https://github.com/bintray/gradle-bintray-plugin)
32+
repo = 'bootstrap'
33+
user = 'shipkit-bootstrap-bot'
34+
userOrg = 'shipkit-bootstrap'
35+
name = 'maven'
36+
licenses = ['MIT']
37+
labels = ['continuous delivery', 'release automation', 'shipkit']
38+
}
39+
}
40+
}
41+
}
-52.3 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Dec 31 15:46:08 BRT 2016
1+
#Thu Oct 12 16:43:02 BDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip

gradle/gradletaskdemo/aplugin.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
task fromPlugin {
2+
doLast {
3+
println "I'm from plugin"
4+
}
5+
}

gradle/gradletaskdemo/build.gradle

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
buildscript {
2+
repositories {
3+
maven {
4+
url "https://plugins.gradle.org/m2/"
5+
}
6+
}
7+
dependencies {
8+
classpath "org.shipkit:shipkit:0.9.117"
9+
}
10+
}
11+
12+
13+
plugins {
14+
id 'java'
15+
}
16+
17+
18+
apply from: 'aplugin.gradle'
19+
apply plugin: 'org.shipkit.bintray-release'
20+
21+
22+
//hello task
23+
task hello {
24+
doLast {
25+
println 'Baeldung'
26+
}
27+
}
28+
29+
//Groovy in gradle task
30+
task toLower {
31+
doLast {
32+
String someString = 'HELLO FROM BAELDUNG'
33+
println "Original: " + someString
34+
println "Lower case: " + someString.toLowerCase()
35+
}
36+
}
37+
38+
39+
// Task dependencies
40+
task helloGradle {
41+
doLast {
42+
println 'Hello Gradle!'
43+
}
44+
}
45+
46+
task fromBaeldung(dependsOn: helloGradle) {
47+
doLast {
48+
println "I'm from Baeldung"
49+
}
50+
}
51+
52+
53+
//Adding behavior to a task via api
54+
task helloBaeldung {
55+
doLast {
56+
println 'I will be executed second'
57+
}
58+
}
59+
60+
helloBaeldung.doFirst {
61+
println 'I will be executed first'
62+
}
63+
64+
helloBaeldung.doLast {
65+
println 'I will be executed third'
66+
}
67+
68+
helloBaeldung {
69+
doLast {
70+
println 'I will be executed fourth'
71+
}
72+
}
73+
74+
75+
76+
77+
//Adding extra task properties
78+
task ourTask {
79+
ext.theProperty = "theValue"
80+
}
81+
82+
task printTaskProperty {
83+
doLast {
84+
println ourTask.theProperty
85+
}
86+
}
87+
88+
89+
90+
//Declaring dependencies
91+
dependencies {
92+
compile group:
93+
'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE'
94+
compile 'org.springframework:spring-core:4.3.5.RELEASE',
95+
'org.springframework:spring-aop:4.3.5.RELEASE'
96+
compile(
97+
[group: 'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE'],
98+
[group: 'org.springframework', name: 'spring-aop', version: '4.3.5.RELEASE']
99+
)
100+
testCompile('org.hibernate:hibernate-core:5.2.12.Final') {
101+
transitive = true
102+
}
103+
runtime(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final') {
104+
transitive = false
105+
}
106+
runtime "org.codehaus.groovy:groovy-all:2.4.11@jar"
107+
runtime group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.11', ext: 'jar'
108+
109+
compile fileTree(dir: 'libs', include: '*.jar')
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+

gradle/gradlew

+25-21
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,30 @@
66
##
77
##############################################################################
88

9-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10-
DEFAULT_JVM_OPTS=""
9+
# Attempt to set APP_HOME
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ] ; do
14+
ls=`ls -ld "$PRG"`
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=`dirname "$PRG"`"/$link"
20+
fi
21+
done
22+
SAVED="`pwd`"
23+
cd "`dirname \"$PRG\"`/" >/dev/null
24+
APP_HOME="`pwd -P`"
25+
cd "$SAVED" >/dev/null
1126

1227
APP_NAME="Gradle"
1328
APP_BASE_NAME=`basename "$0"`
1429

30+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31+
DEFAULT_JVM_OPTS=""
32+
1533
# Use the maximum available, or set MAX_FD != -1 to use that value.
1634
MAX_FD="maximum"
1735

@@ -30,6 +48,7 @@ die ( ) {
3048
cygwin=false
3149
msys=false
3250
darwin=false
51+
nonstop=false
3352
case "`uname`" in
3453
CYGWIN* )
3554
cygwin=true
@@ -40,26 +59,11 @@ case "`uname`" in
4059
MINGW* )
4160
msys=true
4261
;;
62+
NONSTOP* )
63+
nonstop=true
64+
;;
4365
esac
4466

45-
# Attempt to set APP_HOME
46-
# Resolve links: $0 may be a link
47-
PRG="$0"
48-
# Need this for relative symlinks.
49-
while [ -h "$PRG" ] ; do
50-
ls=`ls -ld "$PRG"`
51-
link=`expr "$ls" : '.*-> \(.*\)$'`
52-
if expr "$link" : '/.*' > /dev/null; then
53-
PRG="$link"
54-
else
55-
PRG=`dirname "$PRG"`"/$link"
56-
fi
57-
done
58-
SAVED="`pwd`"
59-
cd "`dirname \"$PRG\"`/" >/dev/null
60-
APP_HOME="`pwd -P`"
61-
cd "$SAVED" >/dev/null
62-
6367
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6468

6569
# Determine the Java command to use to start the JVM.
@@ -85,7 +89,7 @@ location of your Java installation."
8589
fi
8690

8791
# Increase the maximum file descriptors if we can.
88-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
92+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
8993
MAX_FD_LIMIT=`ulimit -H -n`
9094
if [ $? -eq 0 ] ; then
9195
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then

gradle/gradlew.bat

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
@rem Set local scope for the variables with windows NT shell
99
if "%OS%"=="Windows_NT" setlocal
1010

11-
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12-
set DEFAULT_JVM_OPTS=
13-
1411
set DIRNAME=%~dp0
1512
if "%DIRNAME%" == "" set DIRNAME=.
1613
set APP_BASE_NAME=%~n0
1714
set APP_HOME=%DIRNAME%
1815

16+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17+
set DEFAULT_JVM_OPTS=
18+
1919
@rem Find java.exe
2020
if defined JAVA_HOME goto findJavaFromJavaHome
2121

@@ -46,7 +46,7 @@ echo location of your Java installation.
4646
goto fail
4747

4848
:init
49-
@rem Get command-line arguments, handling Windowz variants
49+
@rem Get command-line arguments, handling Windows variants
5050

5151
if not "%OS%" == "Windows_NT" goto win9xME_args
5252
if "%@eval[2+2]" == "4" goto 4NT_args

gradle/greeter/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.gradle
2+
/build
3+
/bin

gradle/greeter/build.gradle

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apply plugin : 'java'
2+
apply plugin : 'application'
3+
4+
5+
6+
dependencies {
7+
compile project(':greeting-library')
8+
compile project(':greeting-library-java')
9+
}
10+
11+
mainClassName = 'greeter.Greeter'
12+
run {
13+
if (project.hasProperty("appArgs")) {
14+
args Eval.me(appArgs)
15+
}
16+
else
17+
args = ["Baeldung"];
18+
}

0 commit comments

Comments
 (0)