I have a Spring project using Gradle that I want to package and upload to a maven repository to be used as a dependency in other Gradle projects. I tried using the maven-publish plugin to do this but the generated JAR has two issues -
1. it is generating a fat jar.
2. there is no pom.xml or any other file in jar that would tell the consumer project about the project's dependencies.
How can I accomplish the two tasks?
Related
I'm having a spring based project which does not have any build management tools like maven/gradle. For dependencies I'm adding the jar files to the build path. Some dependencies like aws-java-sdk and others having only pom.xml files in their jar files. These additional dependencies for the jar files are not getting downloaded from maven central repo. Is there any additional configuration need to be done for this?
For dependency resolution, you need a build tool.
The standard tools nowadays are Maven or Gradle.
I'm new to the maven tool, below is what I have understood about plugins and dependency:
Plugin is a Jar file which executes the task, and dependency is a Jar which provides the class files to execute the task.
What is the difference in maven between dependency and plugin tags in pom xml?
When I define something in the dependency tag, nothing is downloaded to my target folder. Whereas the same thing defined in the plugin tag downloads it in the target folder. Why plugin unpacks the jar file?
Update:
Plugins were unpacked as it was defined in the goal of the plugin.
Plugins and dependencies are completely different things.
Plugins are used by Maven during the build. They form the different parts of the build.
Dependencies are artifacts that should be used by the Java program you create in your build.
So you e.g. need the Maven compiler plugin to compile the code, but add guava as a dependency if your application wants to use guava.
When i define something in dependency tag, nothing is downloaded to my
target folder.
Exactly, all dependencies are placed into $USER_HOME/.m2/repository. They can be used by other mvn projects.
Whereas same thing defined in plugin tag downloads it in target folder. Why > plugin unpacks the jar file?
Can you share your pom.xml? It may depend on your configuration.
How can I tell maven to include dependency jar files while building a fat jar, rather than unpacking them to .class files?
I have a vertx 3.6.0 project producing a fat jar. I am using vertx-maven-plugin:1.0.13, and I run mvn clean package to build. In order to take advantage of Veracode SCM (static scanning), the dependencies inside my fat jar have to be intact, meaning the original dependency jar files have to be contained inside my fat jar. Maven is unpacking all dependencies though, so all I have are class files.
We have another spring boot project which works as expected. It seems the final spring boot repackage goal puts all the dependency jar files in the BOOT-INF dir inside the jar file.
Final 2 goals using vertx-maven-plugin:
maven-jar-plugin:2.4:jar
vertx-maven-plugin:1.0.13:package
Final 2 goals using spring-boot-maven-plugin:
maven-jar-plugin:2.4:jar
spring-boot-maven-plugin:2.1.2.RELEASE:repackage
I've searched the docs for vertx-maven-plugin and all over https://maven.apache.org and elsewhere without any luck so far.
Is there a way to get this same repackage behavior for a non spring boot app?
You can't do that with Vert.x because it doesn't do fancy classloading.
But since it's embeddable, you can create a SpringBoot app that just starts Vert.x. Then you'll get your dependency scanner working.
But I would first check with Veracode if it' can't inspect your POM or Gradle build file instead of scanning a JAR.
If your packaging requirement is for the veracode scan piece, you would probably try packaging your project artifacts into a tar, or zip using the maven-assembly plugin.
Veracode couldn't scan a dependency jar inside another jar for a non-spring boot project. So, you can try one of the following. i) tar packaging using maven-assembler plugin, or ii) convert it to spring-boot project if thats simpler and you could ,or iii) uber-jar creation using maven-shade plugin and need to make some configuration changes for not getting unpackaged to .class files. Still would suggest you can explore with the tar packaging option - (reference:) https://maven.apache.org/plugins/maven-assembly-plugin/
I would like to use Maven to download a "fat" jar- one that includes all of its dependencies. (The same sort of jar that is built using the jar-with-dependencies descriptor Ref in the maven-assembly-plugin)
The default behavior of mvn dependency:copy is to download the jar and all of its dependencies in separate files. This is not what I want. I want the dependencies to be included in the jar itself.
How do I achieve this using Maven? If it's not possible, is there some sort of manual way of assembling the fat jar myself given all its dependency JARs?
In every site I can find only examples, where Dropwizard project is built using Shade pluign Is there any way to build Dropwizard project without shade plugin. If so please provide some sample pom.xml.
If you don't include the shade plugin in your pom, Dropwizard will build correctly and Maven will give you a jar containing all of your project files but none of your dependencies.