Muhammad Talha
04/28/2022, 8:29 AMExpression 'jar' cannot be invoked as a function. The function 'invoke()' is not found
. I already added the java
plugin in the plugins
function. Would any one be able to provide some guidance? Thanks!
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.21"
java
application
}
group = "me.talha"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "11"
}
application {
mainClass.set("MainKt")
}
jar {
manifest {
attributes 'Main-Class': 'MainKt'
}
}
Vampire
04/28/2022, 8:43 AMtasks.jar { ... }
.
There is no extension registered that is called "jar".
Just doing without tasks.
is syntactic sugar only available in Groovy DSL, not in Kotlin DSL.
But actually, I'd recommend you don't set the main class attribute on the jar and worse probably try to build a fat jar.
You already applied and configured the "application" plugin, so use it, it builds a proper distribution with all dependencies, your code, additional files you probably configured and generated start scripts with which you can easily start your application. Just use the distZip
or distTar
task to generate a distributable archive of the respective type, or `assemble`and thus also build
to create them both.Muhammad Talha
04/28/2022, 8:54 AMdistZip
command. However when I run the jar i get a no main manifest attribute, in copycurrbranchkt-1.0-SNAPSHOT.jar
error. Any idea why that might be? Is there a way in Gradle to also generate a manifest attribute?Muhammad Talha
04/28/2022, 8:56 AMephemient
04/28/2022, 8:57 AMephemient
04/28/2022, 8:57 AMMuhammad Talha
04/28/2022, 8:58 AMMuhammad Talha
04/28/2022, 8:58 AMVampire
04/28/2022, 8:58 AMVampire
04/28/2022, 8:59 AMOut of curiosity, the generated jar(s) alone should work fine in any projects I want to use it in right?Heavily depends on what you mean with that
Vampire
04/28/2022, 8:59 AMVampire
04/28/2022, 8:59 AMephemient
04/28/2022, 9:00 AMephemient
04/28/2022, 9:02 AMapplication
plugin?)Muhammad Talha
04/28/2022, 9:02 AMMuhammad Talha
04/28/2022, 9:03 AMVampire
04/28/2022, 9:03 AM