Gradle tutorial project : (#2922)
* Gradle tutorial project : 1. A multi-project build 2. Inclusive all required tasks and dependency example. * Gradle tutorial is shifted to gradle folder
This commit is contained in:
parent
9f497981fd
commit
9caf73c18e
|
@ -0,0 +1 @@
|
|||
/.gradle/
|
|
@ -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
|
|
@ -1,25 +1,35 @@
|
|||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies{
|
||||
compile 'org.springframework:spring-context:4.3.5.RELEASE'
|
||||
|
||||
subprojects {
|
||||
|
||||
version = '1.0'
|
||||
}
|
||||
|
||||
task hello {
|
||||
println "this Baeldung's tutorial is ${awesomeness}"
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
println 'This will be executed during the configuration phase.'
|
||||
|
||||
task configured {
|
||||
println 'This will also be executed during the configuration phase.'
|
||||
}
|
||||
|
||||
uploadArchives {
|
||||
repositories {
|
||||
mavenDeployer {
|
||||
repository(url: 'http://yourmavenrepo/repository') {
|
||||
authentication(userName: 'user', password: 'password');
|
||||
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.'
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
awesomeness=awesome
|
||||
group=com.baeldung.tutorial
|
||||
version=1.0.1
|
|
@ -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']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
task fromPlugin {
|
||||
doLast {
|
||||
println "I'm from plugin"
|
||||
}
|
||||
}
|
|
@ -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')
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Manifest-Version: 1.0
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
/.gradle
|
||||
/build
|
||||
/bin
|
|
@ -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"];
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
|
||||
|
||||
|
||||
public class TestGreeting{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
/build
|
||||
/bin
|
|
@ -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'
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
/build/
|
|
@ -0,0 +1,10 @@
|
|||
package greeter
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class GreetingFormatter{
|
||||
static String greeting(final String name) {
|
||||
"Hello, ${name.capitalize()}"
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package greeter
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class GreetingFormatter{
|
||||
static String greeting(final String name) {
|
||||
"Hello, ${name.capitalize()}"
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
|
||||
}
|
||||
}
|
|
@ -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.'
|
|
@ -1,5 +0,0 @@
|
|||
public class Main{
|
||||
public static void main(String[] args){
|
||||
System.out.println("Baeldung Rocks");
|
||||
}
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue