Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daggerok/4f5f63448f24d991c273165615baa39a to your computer and use it in GitHub Desktop.
Save daggerok/4f5f63448f24d991c273165615baa39a to your computer and use it in GitHub Desktop.

Example of jatJar task using Gradle Kotlin DSL:

val mainClass = "com.github.daggerok.Main" // replace it!

tasks {
  register("fatJar", Jar::class.java) {
    archiveClassifier.set("all")
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
      attributes("Main-Class" to mainClass)
    }
    from(configurations.runtimeClasspath.get()
        .onEach { println("add from dependencies: ${it.name}") }
        .map { if (it.isDirectory) it else zipTree(it) })
    val sourcesMain = sourceSets.main.get()
    sourcesMain.allSource.forEach { println("add from sources: ${it.name}") }
    from(sourcesMain.output)
  }
}
@kavithareddyedula
Copy link

ktor:
environment: $ENV. this is my application.yaml file how to pass $ENV value from ./gradlew runFatJar command

@daggerok
Copy link
Author

daggerok commented Apr 19, 2023

@kavithareddyedula you can pass environment variables like so

unix systems:

ENV=myvalue123 ./gradlew runFatJar

windows:

set ENV=myvalue123
gradlew runFatJar

but ENV variable itself should be used on application run, not build so when you will be running app you should be doing same:

unix:

ENV=myvalue123 java -jar ./build/libs/*.jar

windows:

set ENV=myvalue123
java -jar ./build/libs/*.jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment