Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Gradle for CHTTL

No description
by

on 3 February 2016

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Gradle for CHTTL

Static Code Analysis
Make sure the Code is same style, same convention, easy maintain
Findbugs earlier and fix it
Continuous Integration with
Caty Lee & Derek Yang
Build Process of CI
Prepare Integration Test ENV.
"Create a DevStack ENV"

Unit Test
What & Why Gradle?
"It's a
task based
build system"
"Groovy based
DSL
"
"Gradle is
flexible & progammable
"
"Scalable, support
multi-project build
"
"Better dependency management story"
"Parallel run tests, Fast!"
Who use Gradle?
Compare with Maven
Dependency Management & Conflict
XML vs DSL
Plugin &
Self-defined goal
$gradle init --type java-library

[dependency of
Maven
pom.xml]
<dependencies>
<dependency>
<groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
  </dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
  <version>6.9.4</version>
</dependency>
</dependencies>

[dependency of
Gradle
build.gradle]
dependencies {
  testCompile 'junit:junit:4.11‘
testCompile 'org.testng:testng:6.9.4'
}

[
Maven
repository in your PC local settings.xml ]
[
Gradle
repository in build.gradle]
<repository>
<id>cht-cloud-repo</id>
<name>CHT Cloud Maven Repository</name>
<url>http://10.144.190.145/nexus/content/groups/public/</url>
<releases>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</releases>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>cht-floccus-repo</id>
<name>CHT Floccus Maven Repository</name>
<url>http://10.144.190.145/nexus/content/repositories/</url>
<releases><updatePolicy>always</updatePolicy></releases>
<snapshots><updatePolicy>always</updatePolicy></snapshots>
</repository>
<repository>
<id>clouds-commons</id>
<url>http://10.144.190.145/nexus/content/groups/clouds-commons/</url>
<releases><updatePolicy>always</updatePolicy></releases>
<snapshots><updatePolicy>always</updatePolicy></snapshots>
</repository>
<repository>
<id>repository.jboss.org</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
repositories {
maven {
name "chtCloudRepo"
url "http://10.144.190.145/nexus/content/groups/public/"
}
maven {
name "chtFloccusRepo"
url "http://10.144.190.145/nexus/content/repositories/"
}
maven {
name 'cloudsCommons'
url "http://10.144.190.145/nexus/content/groups/clouds-commons/"
}
maven {
name 'jbossRelease'
url 'https://repository.jboss.org/nexus/content/repositories/releases/'
}
mavenCentral()
mavenLocal()
flatDir name 'localLibDir'
dirs:'lib' flatDirs:['lib1', 'lib2']
}
Lib conflict
[Maven]
When spring beans boot, then find out...?
It's too late!
[Gradle]
Gradle default newest dependency
dependencies {
compile 'commons-collections:commons-collections:3.2'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:
1.2
'
}
[build.gradle]
[run #gradle dependencies]
Gradle fail dependency strategy
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
}
dependencies {
compile 'commons-collections:commons-collections:3.2'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:
1.2
'
}
[build.gradle]
[run #gradle dependencies]
Plugin
[pom.xml]
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.12.1</version>
    <executions>
        <execution>
            <configuration>
                <configLocation>config/checkstyle/checkstyle.xml</configLocation>
                <consoleOutput>true</consoleOutput>
                <failsOnError>true</failsOnError>
            </configuration>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>2.5.4</version>
    <executions>
        <execution>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

[build.gradle]
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
Self Define Task
[Maven]
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>

<echo>"Hello Maven World!"</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[Gradle]
task helloGradle << {
println "Hello Gradle "
}

task world(dependsOn:'helloGradle') <<{
println "World!"
}
Publish Reports
Developer
Code Review
Build Code
Run UnitTests
Code Coverage
Build Artifact
Set-up Test Env
and Deploy
Run IntegrationTest/Functional Tests
Static Code
Analysis
Unit Tests
Set-up Testbed
and Deploy
Run IntegrationTest/Functional Tests
Before Commit Code,
Developer should do....

Gradle Basic
http://www.slideshare.net/tomek_k/gradle-talk-javarsovia-2010
parent pom vs custom plugin
archetype vs free
Java Project
Add Depedency
Multi-Project
Add Test
gradlew
clean build
Install Gradle
Download Lateset(2.9) Gradle and unzip http://gradle.org/gradle-download/
[Windows CLI]
paste the path of Gradle bin to environment parameter
open cmd and Run
install Gradle IDE plugin
[Eclipse]
right click project and run tasks
./gradlew
clean build
[windows]
[linux]
JDK is required!!!
SourceSet
Gradle Concept
#gradle clean
#gradle build
#gradle test
#gradle test --parallel
#gradle jar
#gradle dependencies
#gradle test
#gradle test --parallel
#gradle projects
# settings.gradle file is declaring
sub-projects within the root project
# it's required
// settings.gradle:
include "floccus-cloudsdk-gradle",
"floccus-core-common-gradle"


// build.gradle:
allprojects {
group = 'com.cht.floccus'
version = '0.2.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'jacoco'
}

subprojects {
dependencies {
compile("org.slf4j:slf4j-api:${slf4jVersion}")
}
}

project("floccus-core-common-gradle") {
dependencies {
compile(project(":floccus-cloudsdk-gradle"))
}
}
#gradle floccus-core-common-gradle:clean build
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/main/resources'
}
}
test {
java {
srcDir 'src/test/java'
}
resources {
srcDir 'src/test/resources'
}
}
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
Project
Tasks
Dependency
Plugins
Repository
Configuration
apply plugin: 'java'

group = 'cht.floccus'
version = '1.0'

repositories { }

confiugrations { }

dependencies { }

subprojects { }

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'scala'


Language Plugins
apply plugin: 'eclipse'
apply plugin: 'idea'



IDE Plugins
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'application'
apply plugin: 'ear'



Deployment/Packaging Plugins
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'codenarc'
apply plugin: 'sonar'



Reporting Plugins
class Mytask extends DefaultTask {
String foo
}

task mytask(type: Mytask)

mytask {
foo = 'one'
}

mytask << {
println foo
}



repositories {
mavenLocal()
mavenLocal()
jcenter()
}



configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}



dependencies {
runtime "postgresql:postgresql:$postgresqlVersion"

runtime file("lib/chtMember-1.0.0.jar")

compile project(":floccus-cloudsdk")
}



Integration Test
#gradle check

or

#gradle checkstyle
#gradle findbugs
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'codenarc'

Also can use Eclipse CheckStyle & Findbugs plugin
apply plugin: 'java'
#gradle test


small test
gradle support testng
Also can use Eclipse TestNG plugin
[Let's demo!]
CheckStyle
FindBugs
UnitTests
IntegrationTests
Code Coverage Report
Report
"Install local MongoDB & RabbitMQ (Optional)"
test between modules
#gradle jettyRun
#gradle integrationTest

or Use TestNG!


DB migration Tool
Deployment Pain Points
db script is out of control
migrate with manual process
team member share a db
what the version of the db?
who chages the db?
can not rollback
always need Steed Lai XD

Liquibase
db version control tool
auto migrate to current version
multi-db support
All change to db are store in XML, Json, Yml or SQL
support tag, rollback
can generate chnagelog from existed db

Why Database Tool?
production IoT node 1
production IoT node 2
production CHT node 1
production CHT node 2
production xxx node 1
production xxx node 2
Test A
Test D
Test B
Test E
Test C
Test XXX
Development Server
CI Server
Developer local test database
"Floccus Database migrate to DevStack DB(or LocalDB)"
Liquibase Basic Concept
Changes
Create Table, Add PK, Add FK, Add Column, Add Index, …
Drop Table, Drop PK, Drop FK, Drop Column, Drop Index, …
Insert, Update, Delete, …

Changes are grouped into changesets
Change(s) that should be applied atomically

Changesets uniquely identified by [Author, ID, File]

Changesets are grouped into changelogs

Changelog can include another changelog
Example
Migration Way
Liquibase DSL
XML
YAML
Rollback
Floccus DB filestructure (current)
migrate_sql (option)
changelogs
changelog-master
Useful Liquibase command
#gradle dropAll
#gradle update
With Spring
2
3
4
5
6
11
12
14
16
17
18
19
22
24
26
27
28
29
40
43
44
45
47
48
49
50
51
52
53
56
59
60
61
62
63
64
65
66
67
Java Plugin - tasks
lead to dependency hell easily
custom your project layout
 Write your code & configs
Static Code Analysis
Java plugin tasks inheritance
Full transcript