'Maven "Thin Jar" won't pull library from private gitlab repository
I have a java Spring Boot app which is being packaged into a "thin jar" using the spring boot maven thin jar plugin. I followed instructions from here https://www.baeldung.com/spring-boot-thin-jar and it's all working great. I can deploy new versions of my app in lightweight jars while the production server running the app maintains its own .m2 repository, updating if the new thin jar lists any new dependencies.
Recently I wanted to include my own external library. This is hosted in a gitlab-maven package repository and accessed via an access token. I set this up following instructions here: https://docs.gitlab.com/ee/user/packages/maven_repository/
I've written a settings.xml and saved to home/user/.m2/settings.xml which includes the access token.
After that any mvn ... command is pulling the library into the repository as expected. So far so good.
However when I create my thin jar and try to run with java -jar thin-jar.jar it fails to get the library. The error is as follows:
$ java -Dthin.trace=true -jar thin-jar.jar
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.ThinJarLauncher launch
INFO: Version: 1.0.28.RELEASE
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.PathResolver resolve
INFO: Extracting dependencies from: jar:file:/home/user/thin-jar.jar!/, with profiles []
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.PathResolver loadProperties
INFO: Searching for properties in: jar:file:/home/user/thin-jar.jar!/
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.PathResolver loadProperties
INFO: Searching for properties in: classpath:/
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.PathResolver loadProperties
INFO: Searching for properties in: file:./
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.PathResolver extract
INFO: Extracting dependencies from: URL [jar:file:/home/user/thin-jar.jar!/META-INF/maven/my.group/thin-jar/pom.xml], with profiles []
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.MavenSettingsReader loadSettings
INFO: Reading settings from: /home/user/.m2/settings.xml
May 20, 2022 4:49:24 PM org.springframework.boot.loader.thin.DependencyResolver dependencies
INFO: Computing dependencies from pom and properties
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.wrapper.ThinJarWrapper.launch(ThinJarWrapper.java:139)
at org.springframework.boot.loader.wrapper.ThinJarWrapper.main(ThinJarWrapper.java:107)
Caused by: java.lang.RuntimeException: Failed to read artifact descriptor for my.group:external-library:jar:0.0.1-dev
at org.springframework.boot.loader.thin.DependencyResolver.dependencies(DependencyResolver.java:239)
at org.springframework.boot.loader.thin.PathResolver.extract(PathResolver.java:259)
at org.springframework.boot.loader.thin.PathResolver.resolve(PathResolver.java:105)
at org.springframework.boot.loader.thin.ThinJarLauncher.getClassPathArchives(ThinJarLauncher.java:369)
at org.springframework.boot.loader.thin.ThinJarLauncher.getClassPathArchives(ThinJarLauncher.java:352)
at org.springframework.boot.loader.thin.ThinJarLauncher.getClassPathArchivesIterator(ThinJarLauncher.java:200)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:55)
at org.springframework.boot.loader.thin.ThinJarLauncher.launch(ThinJarLauncher.java:195)
at org.springframework.boot.loader.thin.ThinJarLauncher.main(ThinJarLauncher.java:141)
... 6 more
I'm assuming this is because the repository is private and somewhere along the way the authentication is failing while trying to pull that library? Looking at the trace it appears to load the settings file properly, so where is it going wrong?
Solution 1:[1]
Why does fstream create a file in the executable location?
You used a relative path name. Your operating system interprets relative paths to be relative to the "current working directory" (or similar). If the current working directory is bin, then you will open the file bin/first_file_with_fstream.txt.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Remy Lebeau |
