I am trying to build a Java project that I am going to eventually build into an executable Jar file. My Java project has some dependencies which are not packed inside my Jar file. So how can I make it so, so that when I run my jar file it will automatically download all the dependencies needed for it in order to run properly.
I dont want my jar file to be a fat jar file.
My Current build.gradle file looks like this:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/8.0.1/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
// This dependency is used by the application.
implementation 'com.google.guava:guava:31.1-jre'
implementation 'com.pi4j:pi4j-core:2.3.0'
// implementation 'com.pi4j:pi4j-ktx:2.3.0' // Kotlin DSL
implementation("com.pi4j:pi4j-plugin-raspberrypi:2.2.1")
implementation("com.pi4j:pi4j-plugin-pigpio:2.2.1")
}
application {
// Define the main class for the application.
mainClass = 'new_folder.App'
}
jar {
manifest {
attributes 'Main-Class': application.mainClass
}
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}