Gradle – Advanced training – Agenda



Gradle – Advanced training – Agenda

0 0


advanced-gradle-training


On Github paweloczadly / advanced-gradle-training

Gradle

Advanced training

Pawel Oczadly

Free online version

Agenda

File Operations Build Development Dependency Management

File Operations

Copy Rename Zip Filter

Build Development

build.gradle file Apply from Task types Gradle plugin Multi module project

Dependency Managament

Configurations Types of dependencies Dependency resolution Dependency cache Resolution strategy

File Operations

Copy

task copy(type: Copy) {
    from 'src/main/resources'
    into 'build/resources'
}
						

File Operations

Complex copy

task complexCopy(type: Copy) {
    from('src/main/resources') {
        include '*.xml'
        exclude '**/secure*.properties'
    }
    from('deployment')
    from('config') {
        include '*.sql'
        into 'config'
    }
    into 'build/resources'
}
						

File Operations

Copy quiz

  • Create copy task which copies all except for qa deployment settings to build dir.
  • Put modules.xml and init.sql in build/config dir.
.
├── config
│   └── init.sql
├── deployment
│   ├── prod.properties
│   ├── qa.properties
│   ├── qa2.properties
│   └── staging.properties
└── src
    └── main
        └── resources
            └── modules.xml
						

File Operations

Copy quiz expected solution

build
├── config
│   ├── init.sql
│   └── modules.xml
├── prod.properties
└── staging.properties
						

File Operations

Copy quiz solution

task copy(type: Copy) {
    from ('config') {
        into 'config'
    }
    from ('src/main/resources') {
    	into 'config'
    }
    from ('deployment') {
        exclude 'qa*'
    }
    into 'build'
}
						

File Operations

Rename

task rename(type: Copy) {
	from 'src/main/resources'
	into 'build'
	rename ('modules.xml', 'extensions.xml')
}
						

Allows to rename file(s) during copy.

File Operations

Complex rename

task rename(type: Copy) {
    from('src/main/resources') {
        rename {
            "intci-$it"
        }
        include '**/*.properties'
    }
    from('config') {
        rename {
            "jenkins-${(it - 'dev')}"
        }
    }
    into 'build'
}
						

File Operations

Unzip

task unzip(type: Copy) {
	from zipTree('target.zip')
	into 'destination'
}
						

File Operations

Zip

task zip(type: Zip) {
	classifier = 'target'
	from 'src'
}
						

Zip task documentation.

File Operations

Zip & unzip quiz

  • Create zip package which contains deployment configuration for qa envs.
  • Extract the package to packages dir
.
├── config
│   └── init.sql
├── deployment
│   ├── prod.properties
│   ├── qa.properties
│   ├── qa2.properties
│   └── staging.properties
└── src
    └── main
        └── resources
            └── modules.xml
						

File Operations

Zip solution

task zip(type: Zip) {
	classifier = 'qa-conf'
	from('deployment') {
		include '**/qa*.properties'
	}
}
						

File Operations

Unzip solution

task unzip(type: Copy) {
	from zipTree('qa-conf.zip')
	into 'packages'
}
						

tbc...

Q&A