Noor
Noor

Reputation: 20178

Maven dependency as module

I am not very well versed in maven and I am getting confused on how to handle the following use cases in maven.

There is an open source framework which is on maven. I want to be able to extend this framework. While extending, I also want to test that the extension is correct. So, I want one project which also contains the framework and the test application.

I tried something which is not working. I created a maven project samplejsonextend with two modules:

samplejsonextend pom.xml:

<?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">
    <parent>
        <artifactId>samplejsonextend</artifactId>
        <groupId>com.samplejsonextend</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.samplejsonextend.JSONPathTest</groupId>
    <artifactId>JSONPathTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.2.0</version>
        </dependency>
    </dependencies>
</project>

Module1 (JSONPath) pom.xml :

<?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">
    <parent>
        <artifactId>samplejsonextend</artifactId>
        <groupId>com.samplejsonextend</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>


    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <version>2.2.0</version>
</project>

Module2 (JSONPathTest) pom.xml :

<?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">
    <parent>
        <artifactId>samplejsonextend</artifactId>
        <groupId>com.samplejsonextend</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.samplejsonextend.JSONPathTest</groupId>
    <artifactId>JSONPathTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.2.0</version>
        </dependency>
    </dependencies>
</project>

The issue with the above configuration is that no code is downloaded for module1. Is that the proper way of achieving this? If yes, then can I get some hints for why it is not working? If it's not the proper way, then how can this be achieved?

Upvotes: 0

Views: 141

Answers (1)

CoDel
CoDel

Reputation: 173

Can you try this ?

samplejsonextend pom.xml:

<?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">

    <artifactId>samplejsonextend</artifactId>
    <groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>


<modules>
    <module>JSONPathTest</module>
    <module>JSONPath</module>
</modules>

</project>

Module1 (JSONPath) pom.xml:

<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">
<parent>
    <artifactId>samplejsonextend</artifactId>
    <groupId>com.samplejsonextend</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>samplejsonextend</groupId>
<artifactId>JSONPath</artifactId>
<version>1.0-SNAPSHOT</version>
</project>

Module1 (JSONPathTest) pom.xml:

   <?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">
<parent>
    <artifactId>samplejsonextend</artifactId>
    <groupId>com.samplejsonextend</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

    <groupId>com.samplejsonextend</groupId>
<artifactId>JSONPathTest</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
    <groupId>com.samplejsonextend</groupId>
        <artifactId>JSONPath</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
</project>

With the arbo :

samplejsonextend

  • JSONPath

  • JSONPathTest

The code of the library will be on the classpath so you will be able to extend it.

In your case in the parent pom !

<?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>com.samplejsonextend</groupId>
<artifactId>samplejsonextend</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>

<modules>
    <module>jsonpath</module>
    <module>JSONPathTest</module>
</modules>


 </project>

Upvotes: 1

Related Questions