Hi! Can someone please help me to solve this quest...
# server
m
d
Not sure of the exact error, but if you're trying to build a single Jar file (looks like maybe you are), maybe just use shadow instead? https://imperceptiblethoughts.com/shadow/
👀 1
a
is that the error you see when building the project, or when you try to run the resulting jar file?
m
It's when I try runninng
./gradlew jar
@Alex Ostrovsky Yeah @dave I think I am 😅 Is there a better way of building Jars?
What is shadow by the way @dave
d
Shadow bundles all of your project and dependencies into a single jar.
a
Copy code
plugins {
 id("com.github.johnrengelman.shadow") version "7.0.0"
}
tasks.named<ShadowJar>("shadowJar") {
    isZip64 = true
    manifest {
        attributes(mapOf("Main-Class" to "MainKt"))
    }
}
👀 1
m
Ah understood Thanks for the snippet @Alex Ostrovsky
I am getting this error
Copy code
An exception occurred applying plugin request [id: 'com.github.johnrengelman.shadow', version: '7.0.0']
> Failed to apply plugin class 'com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin'.
   > This version of Shadow supports Gradle 7.0+ only. Please upgrade.
a
if you're using an older version of Gradle, you can use shadow plugin version "6.1.0"
or alternatively change your gradle-wrapper.properties like this:
Copy code
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
m
Alright, thank you. Let me try 🙂
Nope, still getting an error
Copy code
An exception occurred applying plugin request [id: 'com.github.johnrengelman.shadow', version: '6.1.0']
> Failed to apply plugin class 'com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin'.
   > This version of Shadow supports Gradle 7.0+ only. Please upgrade.
a
which version of Gradle are you using? they right version of the shadow plugin depends on the version of Gradle that's being used
maybe try shadow "5.2.0" or try the latest version of the shadow plugin ("7.0.0") with the latest version of Gradle (7.0.2)
m
I think I might have done something wrong and that might be the reason for that error, let me try again
e
how are you running your jar? the scripts that the application plugin generates should set up the classpath just fine, no need for shadow/überjar
m
The way that I am running my jar is from IntelliJ it gets somehow compiled without the error but when I compile it manually with
./gradlew jar
it throws an error on me
e
Copy code
./gradlew run
or
Copy code
./gradlew installDist
build/install/*/bin/*
m
Task 'run'/'installDir' not found in root project 'foo'.
e
use the built-in
application
plugin, e.g.
Copy code
plugins {
    application
}
and drop the
jar
task
m
Ah right
Let me try
But which is the most recommended way of doing this?
By the way when you said building a single Jar @dave is there a way to build multiple jars and kinda link them?
e
yes, the application plugin also has
assembleDist
,
distTar
, and
distZip
tasks
produces
build/distributions/*.tar
and
build/distributions/*.zip
which contain multiple jars and scripts to launch them
m
Interesting... And which one will be faster when running?
the single jar or multiple jars
e
there should not be any appreciable difference
1
m
Alright thanks for the detailed answers guys! Really appreciate your help. I will play around with all of these solutions and decide the one that works the best for me. Have a fantastic day 🙂
👍 1