0
0

More than 1 year has passed since last update.

Gradle - How to Generate an Runnable JAR File

Last updated at Posted at 2023-02-16
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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0