0

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:

  • Module1. JsonPath (which is the original open source framework)

  • Module2. JSONPathTest (which is the application which uses the
    original framework)

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?

demongolem
  • 9,474
  • 36
  • 90
  • 105
Noor
  • 19,638
  • 38
  • 136
  • 254

1 Answers1

1

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>
CoDel
  • 173
  • 2
  • 15
  • thanks but doesn't work, I've pushed the project with your suggestions on github, it says cyclic reference, link on github: https://github.com/noorbakerally/samplejsonextend – Noor Mar 03 '17 at 13:34
  • at the end of the post. – CoDel Mar 03 '17 at 15:31
  • You just have to remove the com.jayway.jsonpath json-path 2.2.0 part – CoDel Mar 03 '17 at 15:31
  • I did it but doesn't work, I updated the github repo with the new mods you provided – Noor Mar 03 '17 at 15:42
  • or is it because of the command, i'm using ""mvn clean install"" – Noor Mar 03 '17 at 15:47
  • Your project is building. What is the problem ? – CoDel Mar 03 '17 at 18:17
  • the source code of the library jsonpath isn't being downloaded in the project, because my aim is to extend the library and have an application to test it at the same time – Noor Mar 03 '17 at 18:21
  • The purpose of maven is not to download the source code. But the java classes are now in your classpath and you can extends them. If you're IDE doesn't show the source of the library, change your maven settings: http://stackoverflow.com/questions/5780758/maven-always-download-sources-and-javadocs. And re run mvn clean install – CoDel Mar 04 '17 at 09:14
  • what is you're IDE ? – CoDel Mar 04 '17 at 09:17
  • OK so under your project you must have maven:library or something like that. You can consult the source by clicking to this library, IntelliJ automatically decompile them. But you will be not able to edit them. – CoDel Mar 04 '17 at 13:46
  • For exemple if class A is in the library, you will be able to see the source code of A, but extends A, you will have to create class B in your project with B extends A and ad or override methods. – CoDel Mar 04 '17 at 13:52
  • yes i understand, but i wanted to directly access the source code, so it's not possible to have such a project structure using maven ? – Noor Mar 04 '17 at 14:26
  • maybe it is possible if the source code is in the repo, can you try this ? mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl= -Dartifact=com.jayway.jsonpath:json-path:2.2.0:source – CoDel Mar 06 '17 at 07:31
  • forget the repvious commande => mvn -DgroupId=com.jayway.jsonpath -DartifactId=json-path -Dversion=2.2.0 -Dclassifier=sources -DremoteRepositories= org.apache.maven.plugins:maven-dependency-plugin:2.8:get – CoDel Mar 06 '17 at 07:48
  • then go find json-path-2.2.0-sources.jar in your local repo and unzip it, you will have the source code. – CoDel Mar 06 '17 at 07:54
  • when executing the command you gave me, it is properly download the source code, but this was not the aim, i could have manually downloaded the source code, what i'm looking is that the source code automatically gets downloaded into the project as a module, are you getting my point, that's what i was asking in the question ? – Noor Mar 06 '17 at 08:59