The compile configuration has been deprecated for a while and was removed in Gradle 7. You should use implementation instead.

Answer from Andy Wilkinson on Stack Overflow
🌐
Medium
thyanmol.medium.com › using-external-jar-in-springboot-project-7efcf53975b0
Using external jar in springboot project | by Anmol Jain | Medium
November 24, 2023 - STEP 2 : Generate the JAR file for the project using the command below. The resulting JAR can be located in the target folder. Copy this file and paste it into your main project (where you intend to utilize this JAR).
Top answer
1 of 1
1

It looks like this is possible if the JAR files are copied before starting the Spring application. It feels hackish, but it works. Use at your own risk!

You need two classes, one for bootstrapping the external JARs, which will then start the second via a manually created PropertiesLauncher. The bootstrapping class can be a plain old regular Java class (but it can be a Spring Boot Application too) and only the second class needs to be a SpringBootApplication.

// BootstrapApplication.java
public class BootstrapApplication {
  public static void main(String[] args) {
    System.out.println("Please copy JAR files and press Enter ...");
    System.in.read();

    PropertiesLauncher.main(args);
  }
}
// Application.java
@SpringBootApplication
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

In the gradle file, we can switch back to the default JarLauncher, by removing the bootJar task manifest configuration and applying settings via the springBoot configuration block. mainClass will end up as Start-Class in the MANIFEST.MF file.

// build.gradle
springBoot {
    mainClass = 'com.example.customlauncher.BootstrapApplication'
}

In the properties file for the loader, a new property needs to be set, which points to the real application class. The settings in this file are only picked up by PropertiesLauncher and ignored by JarLauncher. In other words: JarLauncher delegates to Start-Class from the manifest file and PropertiesLauncher delegates to loader.main from its properties file.

# .../resources/loader.properties
loader.path=file:/path/to/dir
loader.main=com.example.customlauncher.Application

Spring (Boot) will first call the main method of BootstrapApplication, as specified in the MANIFEST.MF file (controlled via springBoot configuration block in the build.gradle file). In the implementation of this main method, a new PropertiesLauncher is created with the main class set to the "real" application (i.e. Application).

Executing the application is still done via the same invocation:

java -jar build/libs/customlauncher-0.0.1-SNAPSHOT.jar

Any JAR files added to /path/to/dir after the JVM has started, but before calling PropertiesLauncher#main in BootstrapApplication are then available in the classpath and application context as seen from Application.

🌐
Masterspringboot
masterspringboot.com › home › how to use an external jar in a spring boot application
How to use an external JAR in a Spring Boot application - Masterspringboot
December 19, 2022 - On the other hand, you will launch the PropertiesLauncher class but adding in the classpath your Spring Boot application. ... java -cp target/myapp-1.0-SNAPSHOT.jar -Dloader.path=/home/user/extlib org.springframework.boot.loader.PropertiesLauncher
🌐
DZone
dzone.com › coding › frameworks › packaging spring boot apps with external dependencies using maven
Packaging Spring Boot Apps With External Dependencies Using Maven
December 23, 2016 - The application JAR is loaded from lib directory. Logs are being written to logs directory ... Create a distribution directory under src/main/resources. Place the assembly xml, gs-spring-boot- distribution.xml in it.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 49403862 › loading-external-jars-in-spring-boot › 49403998
java - Loading external jars in spring boot - Stack Overflow
Support project is NOT a gradle project but is given compile time dependencies to the required jars. ... @RestController @RequestMapping("/test") public class CustomService implements WebMvcConfigurer { @RequestMapping(value = "/hello", method = RequestMethod.GET) public @ResponseBody String get() { return "Done!!"; } } ... java -cp Support.jar:Main.jar -Dloader.path=Support.jar -Xbootclasspath/p:alpn-boot-8.1.11.v20170118.jar -Dloader.main=com.abc.app.MyApplication org.springframework.boot.loader.PropertiesLauncher
🌐
Spring
docs.spring.io › spring-boot › docs › 1.5.22.RELEASE › reference › html › build-tool-plugins-gradle-plugin.html
67. Spring Boot Gradle plugin
May 18, 2023 - The main class that you want to launch can either be specified using a configuration option, or by adding a Main-Class attribute to the manifest. If you don’t specify a main class the plugin will search for a class with a public static void main(String[] args) method. To build and run a project artifact, you can type the following: $ gradle build $ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar · To build a war file that is both executable and deployable into an external container, you need to mark the embedded container dependencies as belonging to the war plugin’s providedRuntime configuration, e.g.:
🌐
Spring
docs.spring.io › spring-boot › docs › current › gradle-plugin › reference › htmlsingle
Spring Boot Gradle Plugin Reference Guide
The assemble task is automatically ... using java -jar and deployed to an external container. To do so, the embedded servlet container dependencies should be added to the providedRuntime configuration, for example:...
🌐
DEV Community
dev.to › wakeupmh › building-3rd-party-jars-in-spring-maven-project-4mjh
Building 3rd party JARs in Spring (Maven project) - DEV Community
March 19, 2020 - <dependency> <groupId>com.xpto.lib</groupId> <artifactId>XPTO</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/XPTO.jar</systemPath> </dependency> I was facing this error and about getting crazy before finding this solution. In your pom.xml just add this <includeSystemScope>true</includeSystemScope> like this · <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <classifier>exec</classifier> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins>
🌐
Medium
medium.com › @salmankhan_27014 › incorporating-third-party-jar-files-into-a-spring-boot-application-e42e6eca0ffd
Incorporating Third-Party JAR Files into a Spring Boot Application | by Salman Khan | Medium
February 14, 2023 - Again, make sure to replace groupId, artifactId, and version with the appropriate values for the JAR file you installed. Once you have added the dependency to your pom.xml file, you should be able to use the classes and resources provided by the third-party library in your Spring Boot application.
🌐
Medium
medium.com › @mak0024 › provide-external-jars-for-the-spring-boot-application-c65821ce6368
Provide external jars for the Spring Boot application | by AM | Medium
December 19, 2023 - org.springframework.boot.loader.PropertiesLauncher · What we simply need to do is to include this PropertieLauncher in the class path of the application. -cp <path-to-executable>\executable.jar;<path-to-external-jars>\* org.springframework...
🌐
Baeldung
baeldung.com › home › gradle › local jar files as gradle dependencies
Local JAR Files as Gradle Dependencies | Baeldung
June 24, 2025 - In this tutorial, we’ll focus on how we can add local JAR files to our Gradle dependencies.
🌐
Coderanch
coderanch.com › t › 772683 › frameworks › inject-normal-java-class-external
How to inject normal java class from external jar into spring boot application classes (Spring forum at Coderanch)
May 18, 2023 - If you didn't use Maven, Maven ... Boot project and you just want to literally inject it, as Hmai says, you can use the Spring @Autowired annotation if the target is a Spring-managed bean....
🌐
Spring
docs.spring.io › spring-boot › docs › 1.4.1.RELEASE › reference › html › build-tool-plugins-gradle-plugin.html
64. Spring Boot Gradle plugin
The main class that you want to ... or by adding a Main-Class attribute to the manifest. If you don’t specify a main class the plugin will search for a class with a public static void main(String[] args) method. To build and run a project artifact, you can type the following: $ gradle build $ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar · To build a war file that is both executable and deployable into an external container, ...