For Android:
Command:
gradlew jarDebug / gradlew jarRelease
Code:
android.libraryVariants.all { variant ->
task("jar${variant.name}", type: Jar) {
description "Bundles compiled .class files into a JAR file for $variant.name."
dependsOn variant.javaCompile
from variant.javaCompile.destinationDir
exclude '**/R.class', '**/R$*.class', '**/R.html', '**/R.*.html'
}
}
Source: https://stackoverflow.com/a/19967914/950427
Java or Android Project:
task makeJar(type: Copy) {
from('directory1/')
from('directory2/')
into('another directory/')
include('classes.jar')
}
Similar: https://stackoverflow.com/a/19037807/950427
Example:
task initConfig(type: Copy) {
from('src/main/config') {
include '**/*.properties'
include '**/*.xml'
filter(ReplaceTokens, tokens: [version: '2.3.1'])
}
from('src/main/config') {
exclude '**/*.properties', '**/*.xml'
}
from('src/main/languages') {
rename 'EN_US_(.*)', '$1'
}
into 'build/target/config'
exclude '**/*.bak'
includeEmptyDirs = false
with dataContent
}
Source: http://gradle.org/docs/current/dsl/org.gradle.api.tasks.Copy.html