Include the bytecode of a JAR file in a gradle library vs. just adding it as a dependency - maven

If I add a JAR file to a gradle project's depenencies, the code compiles just fine, but after publishing to maven (publishToMavenLocal), the classes from the JAR are not found.
Obviously, this is because the jar is added as a "dependency" and not part of the project itself. Is there a way to get the contents of the JAR file to merge into the library? Do I need to make a separate maven repo for each JAR?

You can always try to create a fat jar which includes dependencies. You can follow the instructions provided here https://www.baeldung.com/gradle-fat-jar

Related

maven: generate library jar with classes inside a package

I've created a project (springboot service).
I need to generate:
the main executable jar, already managed by spring-boot-maven-plugin
also, I need to generate a non-executable jar from some included classes (everything inside me.jeusdi.serializers package.
Any ideas?
Create a multi-module project which has two modules:
the executable JAR
The non-executable JAR

Why doesn't the dependency contain a jar in the maven public repository https://mvnrepository.com?

I a maven rookie and am wondering how to get a binary jar file if it is not already in the repo. Specifically i'm in need of: jackson-dataformats-text-2.13.0.jar. Do I need to build it myself? I'm used to creating a project and marking a library as a dependency and seeing the jar downloaded into my .m2 cache but all i see in my cache is:
jchan#jchan-Z170N:~/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformats-text/2.13.0$ ls
jackson-dataformats-text-2.13.0.jar.lastUpdated jackson-dataformats-text-2.13.0.pom.sha1
jackson-dataformats-text-2.13.0.pom _remote.repositories
Can someone advise how I am to get a built version of the jar from maven central?
We are still maintaining our ant build and I need the jar file for this. (i know i know, ancient stuff but team is not ready to port just yet).
parent pom don't contain jar file
This is the reason why no bundle link is present on the official public maven repository https://mvnrepository.com
The maven dependency is not a jar, is a parent. So the extension is: .pom which is just a plain pom.xml
Parent dependencies don't contain compiled class like .jar.
In your specific case, there are another dependencies who contains jars:
https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.13.0/
https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-xml/2.13.0/
advice
Check what classes do you need on your ant project and search if exist a jar (with the classes you need) on https://mvnrepository.com
Another option is to get all the dependencies from pom :
https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformats-text/2.9.0/jackson-dataformats-text-2.9.0.pom and download them into your ant project. In theory is the same of add the parent pom in a maven project

Repackaging a dependency as a fat jar

I have two maven projects. One is a library and the other one is an example utilizing this library.
Because my customer is a little old-school he would like to run the example without using maven and requires that the example contains a folder "lib" containing a fat jar file with the lib.
Using maven-assembly-plugin I have been successful in repackaging my lib. as a fat jar but only if it is declared within the lib.'s pom file. But from my POV I would like to have this declaration in the pom file of the example and not the lib. (in order to avoid polluting my lib. with this nonsense).
So my question is: Is it possible to build a fat jar file for a dependency in a maven project? That is, can I use a plugin like maven-assembly-plugin to repackage my lib. as a fat jar from the pom of my example project?

How to pack a jar without dependency classes in gradle similar to maven

How to write a gradle script so that the application jar should be packed without dependency classes similar to maven jar package
The application JAR is always without dependencies, except you use special plugins to create a "fat" JAR where the dependencies are included. If you ask how to set up a Gradle build at all, you should start reading the Users Guide.
If you are trying to package a jar from your Android app or library:
I ran into this question because gradle would include 3rd party libraries into my jar when running gradle assembleRelease.
The contents of the jar then looked like this:
com/android/...
/myCompany/...
For some reason this did not happen when building for debug. Finally I found that changing:
compile 'com.android.support:recyclerview-v7:23.0.0'
to
provided 'com.android.support:recyclerview-v7:23.0.0'
would not include the 3rd party libs ...

How to add a plugin as a jar to a grails project

I created a custom plugin 'myPlugin' for GRAILS. I compiled and installed it as a binary (my-plugin-0.1.jar) file.
The jar file can't be found by grails in a "normal" project, because it only looks for my-plugin-0.1.zip (the plugin is defined within the plugins-block in BuildConfig.groovy)
How can i add the .jar file as a plugin?
Binary plugins packaged as jar has to be referred in the dependencies section instead of the plugins section in BuildConfig
dependencies {
compile "mygroup:myplugin:0.1"
}
or you can put the jar in application's lib directory which I would discourage. :)
Add it in the dependencies block (not plugins) in BuildConfig.groovy.
Publish plugin installs the jar into local maven cache (/.m2). Verify the existence of the jar in .m2.
Also verify if the application using the plugin has mavenLocal enabled in repositories' buildConfig.

Resources