build.gradle
apply plugin: 'java'
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
}
dependencies {
...
...
...skip
}
configurations {
implementation {
canBeResolved = true
}
}
task JarTestExample(type: Jar) {
zip64 = true
duplicatesStrategy = DuplicatesStrategy.INCLUDE
archivesBaseName = 'TestExample'
includeEmptyDirs = false
manifest {
attributes 'Main-Class': 'com.johnny.TestExample'
}
// remove the security files (from mail.jar / activation.jar) so that the jar will be executable.
from (configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
from sourceSets.main.output
}
johnny$ gradle clean JarTestExample