Question

Usually(I seen only such) the maven artifact is one jar. Is it possible to make maven artifact as several jars. Currently I have to add severall thirdparty libs to my nexus - and I want them being reference in maven as one artifact.

Was it helpful?

Solution

Usually(I seen only such) the maven artifact is one jar. Is it possible to make maven artifact as several jars.

That statement is partially true. Yes maven artifacts are a single jar unit but it is highly possible that this single unit of jar may require multiple other jars to function properly. One such example may be of the spring-core jar. If you only add the spring-core jar in your application, it will most probably give you a ClassNotFoundException and complain about mulitple other missing dependencies (like log4j, spring-web, commons, etc etc ). To cope up with this nested dependencies issue, we have the concept of transitive dependencies in maven

Currently I have to add severall thirdparty libs to my nexus

In my opinion, its okay and it is as it should be. All artifacts and jar libraries should be separate.

I want them being reference in maven as one artifact.

Still if you want to create one big (fat) jar, take a look at how to create a uber shaded jar in maven

OTHER TIPS

If you simply want to include them all together, you could create a pom project which has all your thirdparty libraries as dependencies. As a result, you need only to add the pom project as dependency:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.demo</groupId>
<artifactId>all-my-libs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
  <dependency>
    <groupId>l1</groupId>
    <artifactId>lib1</artifactId>
    <version>1.0</version>
  </dependency>
  <dependency>
    <groupId>l2</groupId>
    <artifactId>lib2</artifactId>
    <version>1.0</version>
  </dependency>
  ...
</dependencies>
</project>

That way, you would still have several jars, but only one dependency.

You should read up on pom dependencies with <scope>import</scope> as shown here.

Basically, you need to create pom with all the dependencies you need and then define a dependency to it with scope import.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top