10

Good day,

I have built a project using maven. Throughout this project, I have concluded that one more dependency has to be added for a particular module. I have added this dependency in it's pom file and when I have tried to rebuild the project using maven, a null pointer was thrown.

Pom files before:

(child pom:)

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
    </dependency>

</dependencies>

(main pom:)

    <dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


        <dependency>
            <groupId>com.solveit.crm.core</groupId>
            <artifactId>crm-core</artifactId>
            <version>${project.version}</version>
        </dependency> //this dependency is for another module, it was
                        declared at the start of the project


    </dependencies>
</dependencyManagement>

Pom files now(which cause nullpointer):

(child pom:)

<dependencies>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
    </dependency>

    <dependency>
        <groupId>com.solveit.crm.data</groupId>
        <artifactId>crm-data</artifactId>
    </dependency>

</dependencies>

(main pom:)

<dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


        <dependency>
            <groupId>com.solveit.crm.core</groupId>
            <artifactId>crm-core</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.solveit.crm.data</groupId>
            <artifactId>crm-data</artifactId>
            <version>${project.version}</version>
        </dependency>

    </dependencies>
</dependencyManagement>

Why does maven throw null pointer exception? I am confused right now.

ERROR MESSAGE:

    [INFO] Scanning for projects...
[ERROR] Internal error: java.lang.NullPointerException -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.NullPointerEx
ception
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:167)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
356)
Caused by: java.lang.NullPointerException
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:270)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        ... 11 more
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorE
xception

In eclipse I get:

    [INFO] Scanning for projects...
[ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.solveit.crm.data:crm-data:1'}' and 'Vertex{label='com.solveit.crm.core:crm-core:1'}' introduces to cycle in the graph com.solveit.crm.core:crm-core:1 --> com.solveit.crm.data:crm-data:1 --> com.solveit.crm.core:crm-core:1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectCycleException

Thank you

Bravo
  • 1,944
  • 4
  • 29
  • 53
  • Try maven clean install command under that same project directory using the command window instead of Eclipse. – Jay Apr 15 '14 at 08:47
  • Jay, I have used cmd instead of Eclipse for this – Bravo Apr 15 '14 at 08:49
  • I have tried building this project in eclipse now, and I get a different error. I have edited and added the eclipse error above – Bravo Apr 15 '14 at 08:51
  • possible duplicate of [Can I avoid a dependency cycle with one edge being a test dependency?](http://stackoverflow.com/questions/6034513/can-i-avoid-a-dependency-cycle-with-one-edge-being-a-test-dependency) – Andrei Sfat Apr 15 '14 at 09:03

1 Answers1

14

You have a cyclic reference of dependencies.

It looks like your crm-core project has crm-data in its dependencies and the crm-data project has crm-core in its dependencies.

Maven can't compile such a case.

Fabien Thouraud
  • 909
  • 1
  • 11
  • 21
  • how should I deal in this case? How can I make two modules dependent on each other? – Bravo Apr 15 '14 at 08:57
  • 3
    You can move common classes/resources to a third independent module and make the two existing modules depend on this common module. – ssssteffff Apr 15 '14 at 09:00
  • According to me, you can't. Maybe you can think of another conception for your project. You can use a common module as ssssteffff proposed. – Fabien Thouraud Apr 15 '14 at 09:02
  • Hmm, okay... Thank you guyis, I will keep that in mind next time. Cheers – Bravo Apr 15 '14 at 09:14
  • 17
    I don't think that Maven crashing with a NullPointerException is the best way to explain the cyclic dependency. – djjeck Jun 24 '14 at 23:18
  • If you are using eclipse m2e plugin, it will give you a better error message hinting there is a cyclical dependency. – yellavon Aug 25 '14 at 15:29