Noob
Noob

Reputation: 27

Include jars in pom.xml

So here is the scenario. I have a maven project for which I am using some(7) jars for unit testing. All these jars are present on maven remote/local(.m2) repository. and I have to add them individually as dependency.

I want to create a pom (parent) which contain these jars as dependency so that if I include this pom(parent) as dependency, all 7 dependencies are automatically resolved.

I tried this code but i think there are some issues with packaging type. (pom packaging didn't work either).

<?xml version="1.0" encoding="UTF-8"?>
 <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>some.package</groupId>
 <artifactId>full-PACK</artifactId>
 <version>1.1</version>
 <packaging>jar</packaging>

 <dependencies>

  <dependency>
   <groupId>org.javassist</groupId>
   <artifactId>javassist</artifactId>
   <version>3.21.0</version>
   <scope>test</scope>
  </dependency>

 <!-- 6 more similar dependencies -->

 </dependencies>

</project>

I want this pom to just act as pointer, and this should resolve dependencies in their respective packages not in package of this pom. I don't want to create a fat jar for this pom.

Is there a way in which I can use this pom as kind of pointer so that it just tells project to import those 7 jars?

Upvotes: 1

Views: 494

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35805

I have not tested it, but following the Maven logic, this should work:

Create a project with packaging pom that references the 7 jars as compile dependencies:

<?xml version="1.0" encoding="UTF-8"?>
 <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>some.package</groupId>
 <artifactId>full-PACK</artifactId>
 <version>1.1</version>
 <packaging>pom</packaging>

 <dependencies>

  <dependency>
   <groupId>org.javassist</groupId>
   <artifactId>javassist</artifactId>
   <version>3.21.0</version>
   <scope>compile</scope>
  </dependency>

 <!-- 6 more similar dependencies -->

 </dependencies>

</project>

Now declare a test dependency on this pom in your project like

<dependency>
   <groupId>some.package</groupId>
   <artifactId>full-PACK</artifactId>
   <version>1.1</version>
   <type>pom</type>
   <scope>test</scope>
</dependency>

Your approach failed because test dependencies are not transitive. Have a look at the table on

https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Upvotes: 1

Related Questions