diff --git a/gradle/.gitignore b/gradle/.gitignore new file mode 100644 index 0000000000..da88288c09 --- /dev/null +++ b/gradle/.gitignore @@ -0,0 +1 @@ +/.gradle/ diff --git a/gradle/.travis.yml b/gradle/.travis.yml new file mode 100644 index 0000000000..b2b534799b --- /dev/null +++ b/gradle/.travis.yml @@ -0,0 +1,27 @@ +# More details on how to configure the Travis build +# https://docs.travis-ci.com/user/customizing-the-build/ + +# Speed up build with travis caches +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ + +language: java + +jdk: + - oraclejdk8 + +#Skipping install step to avoid having Travis run arbitrary './gradlew assemble' task +# https://docs.travis-ci.com/user/customizing-the-build/#Skipping-the-Installation-Step +install: + - true + +#Don't build tags +branches: + except: + - /^v\d/ + +#Build and perform release (if needed) +script: + - ./gradlew build -s && ./gradlew ciPerformRelease \ No newline at end of file diff --git a/gradle/build.gradle b/gradle/build.gradle index fc561987f7..dcc592a2b4 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -1,25 +1,35 @@ -apply plugin: 'java' -apply plugin: 'maven' - -repositories{ - mavenCentral() +allprojects { + repositories { + jcenter() + } } -dependencies{ - compile 'org.springframework:spring-context:4.3.5.RELEASE' -} -task hello { - println "this Baeldung's tutorial is ${awesomeness}" +subprojects { + + version = '1.0' } -uploadArchives { - repositories { - mavenDeployer { - repository(url: 'http://yourmavenrepo/repository') { - authentication(userName: 'user', password: 'password'); - } - - } - } +apply plugin: 'eclipse' + +println 'This will be executed during the configuration phase.' + +task configured { + println 'This will also be executed during the configuration phase.' +} + +task execFirstTest { + doLast { + println 'This will be executed during the execution phase.' + } +} + +task execSecondTest { + doFirst { + println 'This will be executed first during the execution phase.' + } + doLast { + println 'This will be executed last during the execution phase.' + } + println 'This will be executed during the configuration phase as well.' } diff --git a/gradle/gradle.properties b/gradle/gradle.properties deleted file mode 100644 index 41701e5a19..0000000000 --- a/gradle/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -awesomeness=awesome -group=com.baeldung.tutorial -version=1.0.1 diff --git a/gradle/gradle/shipkit.gradle b/gradle/gradle/shipkit.gradle new file mode 100644 index 0000000000..144c01dc05 --- /dev/null +++ b/gradle/gradle/shipkit.gradle @@ -0,0 +1,41 @@ +//This default Shipkit configuration file was created automatically and is intended to be checked-in. +//Default configuration is sufficient for local testing and trying out Shipkit. +//To leverage Shipkit fully, please fix the TODO items, refer to our Getting Started Guide for help: +// +// https://github.com/mockito/shipkit/blob/master/docs/getting-started.md +// +shipkit { + //TODO is the repository correct? + gitHub.repository = "unspecified-user/unspecified-repo" + + //TODO generate and use your own read-only GitHub personal access token + gitHub.readOnlyAuthToken = "76826c9ec886612f504d12fd4268b16721c4f85d" + + //TODO generate GitHub write token, and ensure your Travis CI has this env variable exported + gitHub.writeAuthToken = System.getenv("GH_WRITE_TOKEN") +} + +allprojects { + plugins.withId("com.jfrog.bintray") { + + //Bintray configuration is handled by JFrog Bintray Gradle Plugin + //For reference see the official documentation: https://github.com/bintray/gradle-bintray-plugin + bintray { + + //TODO sign up for free open source account with https://bintray.com, then look up your API key on your profile page in Bintray + key = '7ea297848ca948adb7d3ee92a83292112d7ae989' + //TODO don't check in the key, remove above line and use env variable exported on CI: + //key = System.getenv("BINTRAY_API_KEY") + + pkg { + //TODO configure Bintray settings per your project (https://github.com/bintray/gradle-bintray-plugin) + repo = 'bootstrap' + user = 'shipkit-bootstrap-bot' + userOrg = 'shipkit-bootstrap' + name = 'maven' + licenses = ['MIT'] + labels = ['continuous delivery', 'release automation', 'shipkit'] + } + } + } +} diff --git a/gradle/gradle/wrapper/gradle-wrapper.jar b/gradle/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 3391a4cdf6..0000000000 Binary files a/gradle/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/gradle/wrapper/gradle-wrapper.properties b/gradle/gradle/wrapper/gradle-wrapper.properties index b601d97764..ebf7ae9184 100644 --- a/gradle/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Dec 31 15:46:08 BRT 2016 +#Thu Oct 12 16:43:02 BDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip diff --git a/gradle/gradletaskdemo/aplugin.gradle b/gradle/gradletaskdemo/aplugin.gradle new file mode 100644 index 0000000000..ca96c50b54 --- /dev/null +++ b/gradle/gradletaskdemo/aplugin.gradle @@ -0,0 +1,5 @@ +task fromPlugin { + doLast { + println "I'm from plugin" + } +} \ No newline at end of file diff --git a/gradle/gradletaskdemo/build.gradle b/gradle/gradletaskdemo/build.gradle new file mode 100644 index 0000000000..58dadd7460 --- /dev/null +++ b/gradle/gradletaskdemo/build.gradle @@ -0,0 +1,110 @@ +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath "org.shipkit:shipkit:0.9.117" + } +} + + +plugins { + id 'java' +} + + +apply from: 'aplugin.gradle' +apply plugin: 'org.shipkit.bintray-release' + + +//hello task +task hello { + doLast { + println 'Baeldung' + } +} + +//Groovy in gradle task +task toLower { + doLast { + String someString = 'HELLO FROM BAELDUNG' + println "Original: " + someString + println "Lower case: " + someString.toLowerCase() + } +} + + +// Task dependencies +task helloGradle { + doLast { + println 'Hello Gradle!' + } +} + +task fromBaeldung(dependsOn: helloGradle) { + doLast { + println "I'm from Baeldung" + } +} + + +//Adding behavior to a task via api +task helloBaeldung { + doLast { + println 'I will be executed second' + } +} + +helloBaeldung.doFirst { + println 'I will be executed first' +} + +helloBaeldung.doLast { + println 'I will be executed third' +} + +helloBaeldung { + doLast { + println 'I will be executed fourth' + } +} + + + + +//Adding extra task properties +task ourTask { + ext.theProperty = "theValue" +} + +task printTaskProperty { + doLast { + println ourTask.theProperty + } +} + + + +//Declaring dependencies +dependencies { + compile group: + 'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE' + compile 'org.springframework:spring-core:4.3.5.RELEASE', + 'org.springframework:spring-aop:4.3.5.RELEASE' + compile( + [group: 'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE'], + [group: 'org.springframework', name: 'spring-aop', version: '4.3.5.RELEASE'] + ) + testCompile('org.hibernate:hibernate-core:5.2.12.Final') { + transitive = true + } + runtime(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final') { + transitive = false + } + runtime "org.codehaus.groovy:groovy-all:2.4.11@jar" + runtime group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.11', ext: 'jar' + + compile fileTree(dir: 'libs', include: '*.jar') +} diff --git a/gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF b/gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF new file mode 100644 index 0000000000..59499bce4a --- /dev/null +++ b/gradle/gradletaskdemo/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/gradle/gradlew b/gradle/gradlew index 9d82f78915..27309d9231 100644 --- a/gradle/gradlew +++ b/gradle/gradlew @@ -6,12 +6,30 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then diff --git a/gradle/gradlew.bat b/gradle/gradlew.bat index 8a0b282aa6..832fdb6079 100644 --- a/gradle/gradlew.bat +++ b/gradle/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,7 +46,7 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args diff --git a/gradle/greeter/.gitignore b/gradle/greeter/.gitignore new file mode 100644 index 0000000000..e93e09f86e --- /dev/null +++ b/gradle/greeter/.gitignore @@ -0,0 +1,3 @@ +/.gradle +/build +/bin diff --git a/gradle/greeter/build.gradle b/gradle/greeter/build.gradle new file mode 100644 index 0000000000..6f43f23494 --- /dev/null +++ b/gradle/greeter/build.gradle @@ -0,0 +1,18 @@ +apply plugin : 'java' +apply plugin : 'application' + + + +dependencies { + compile project(':greeting-library') + compile project(':greeting-library-java') +} + +mainClassName = 'greeter.Greeter' +run { + if (project.hasProperty("appArgs")) { + args Eval.me(appArgs) + } + else + args = ["Baeldung"]; +} diff --git a/gradle/greeter/src/main/java/greeter/Greeter.java b/gradle/greeter/src/main/java/greeter/Greeter.java new file mode 100644 index 0000000000..7b59f0c4bc --- /dev/null +++ b/gradle/greeter/src/main/java/greeter/Greeter.java @@ -0,0 +1,13 @@ +package greeter; + +import baeldunggreeter.Formatter; + +public class Greeter { + public static void main(String[] args) { + final String output = GreetingFormatter + .greeting(args[0]); + String date = Formatter.getFormattedDate(); + System.out.println(output); + System.out.println("Today is :" + date); + } +} diff --git a/gradle/greeter/src/test/java/greetertest/TestGreeting.java b/gradle/greeter/src/test/java/greetertest/TestGreeting.java new file mode 100644 index 0000000000..0ae5fab631 --- /dev/null +++ b/gradle/greeter/src/test/java/greetertest/TestGreeting.java @@ -0,0 +1,11 @@ + + + + +public class TestGreeting{ + + + + + +} \ No newline at end of file diff --git a/gradle/greeting-library-java/.gitignore b/gradle/greeting-library-java/.gitignore new file mode 100644 index 0000000000..348c102afc --- /dev/null +++ b/gradle/greeting-library-java/.gitignore @@ -0,0 +1,2 @@ +/build +/bin diff --git a/gradle/greeting-library-java/build.gradle b/gradle/greeting-library-java/build.gradle new file mode 100644 index 0000000000..34931bd0cd --- /dev/null +++ b/gradle/greeting-library-java/build.gradle @@ -0,0 +1,9 @@ +apply plugin :'java' +//apply plugin : 'application' + + + +dependencies{ + compile group: 'joda-time', name: 'joda-time', version: '2.9.9' + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java b/gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java new file mode 100644 index 0000000000..367e992c1b --- /dev/null +++ b/gradle/greeting-library-java/src/main/java/baeldunggreeter/Formatter.java @@ -0,0 +1,14 @@ +package baeldunggreeter; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Formatter { + public static String getFormattedDate() { + DateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss"); + Date date = new Date(); + return dateFormat.format(date); + } +} diff --git a/gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java b/gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java new file mode 100644 index 0000000000..49efc934a5 --- /dev/null +++ b/gradle/greeting-library-java/src/test/java/baeldunggreetertest/FormatterTest.java @@ -0,0 +1,23 @@ +package baeldunggreetertest; + +import static org.junit.Assert.assertTrue; + +import java.util.Date; +import java.util.regex.Pattern; + +import org.junit.Test; + +import baeldunggreeter.Formatter; + +public class FormatterTest { + + @Test + public void testFormatter() { + + String dateRegex1 = "^((19|20)\\d\\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]) ([2][0-3]|[0-1][0-9]|[1-9]):[0-5][0-9]:([0-5][0-9]|[6][0])$"; + String dateString = Formatter.getFormattedDate(); + assertTrue(Pattern + .matches(dateRegex1, dateString)); + + } +} \ No newline at end of file diff --git a/gradle/greeting-library/.gitignore b/gradle/greeting-library/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/gradle/greeting-library/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/gradle/greeting-library/bin/greeter/GreetingFormatter.groovy b/gradle/greeting-library/bin/greeter/GreetingFormatter.groovy new file mode 100644 index 0000000000..94c863e294 --- /dev/null +++ b/gradle/greeting-library/bin/greeter/GreetingFormatter.groovy @@ -0,0 +1,10 @@ +package greeter + +import groovy.transform.CompileStatic + +@CompileStatic +class GreetingFormatter{ + static String greeting(final String name) { + "Hello, ${name.capitalize()}" + } +} diff --git a/gradle/greeting-library/bin/greeter/GreetingFormatterSpec.groovy b/gradle/greeting-library/bin/greeter/GreetingFormatterSpec.groovy new file mode 100644 index 0000000000..f1c1211552 --- /dev/null +++ b/gradle/greeting-library/bin/greeter/GreetingFormatterSpec.groovy @@ -0,0 +1,13 @@ +package greeter + +import spock.lang.Specification + +class GreetingFormatterSpec extends Specification { + + def 'Creating a greeting'() { + + expect: 'The greeeting to be correctly capitalized' + GreetingFormatter.greeting('gradlephant') == 'Hello, Gradlephant' + + } +} diff --git a/gradle/greeting-library/build.gradle b/gradle/greeting-library/build.gradle new file mode 100644 index 0000000000..eb526b3b03 --- /dev/null +++ b/gradle/greeting-library/build.gradle @@ -0,0 +1,9 @@ +apply plugin : 'groovy' + +dependencies { + compile 'org.codehaus.groovy:groovy:2.4.12' + + testCompile 'org.spockframework:spock-core:1.0-groovy-2.4', { + exclude module : 'groovy-all' + } +} diff --git a/gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy b/gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy new file mode 100644 index 0000000000..db8a035b67 --- /dev/null +++ b/gradle/greeting-library/src/main/groovy/greeter/GreetingFormatter.groovy @@ -0,0 +1,10 @@ +package greeter + +import groovy.transform.CompileStatic + +@CompileStatic +class GreetingFormatter{ + static String greeting(final String name) { + "Hello, ${name.capitalize()}" + } +} \ No newline at end of file diff --git a/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy b/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy new file mode 100644 index 0000000000..f1c1211552 --- /dev/null +++ b/gradle/greeting-library/src/test/groovy/greeter/GreetingFormatterSpec.groovy @@ -0,0 +1,13 @@ +package greeter + +import spock.lang.Specification + +class GreetingFormatterSpec extends Specification { + + def 'Creating a greeting'() { + + expect: 'The greeeting to be correctly capitalized' + GreetingFormatter.greeting('gradlephant') == 'Hello, Gradlephant' + + } +} diff --git a/gradle/settings.gradle b/gradle/settings.gradle new file mode 100644 index 0000000000..38704681bd --- /dev/null +++ b/gradle/settings.gradle @@ -0,0 +1,10 @@ +rootProject.name = 'gradletutorial' + + +include 'greeting-library' +include 'greeting-library-java' +include 'greeter' +include 'gradletaskdemo' + + +println 'This will be executed during the initialization phase.' diff --git a/gradle/src/main/java/Main.java b/gradle/src/main/java/Main.java deleted file mode 100644 index 10edd1840b..0000000000 --- a/gradle/src/main/java/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main{ - public static void main(String[] args){ - System.out.println("Baeldung Rocks"); - } -} diff --git a/gradle/version.properties b/gradle/version.properties new file mode 100644 index 0000000000..565e9213ae --- /dev/null +++ b/gradle/version.properties @@ -0,0 +1,3 @@ +#Version of the produced binaries. This file is intended to be checked-in. +#It will be automatically bumped by release automation. +version=0.0.1