Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a maven module outside of the project context?

I'd like to have a module in some kind of global project directory, so that I can include that module in all other projects that use that common code.

But how can I then tell a maven parent pom to include and compile this global shared module? The following does not work:

svn/MyGlobalProject/project-commons/pom.xml           //should be shared among different projects
svn/MyProject/web-parent/trunk/pom.xml                //the parent pom used to build the application
svn/MyProject/web-parent/trunk/project-domain/pom.xml //submodule 1
svn/MyProject/web-parent/trunk/project-web/pom.xml    //submodule 2

parent pom.xml:

<project>
        <groupId>de.project</groupId>
    <artifactId>project-parent</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>project-domain</module>
        <module>project-web</module>
        <module>../project-commons</module> <!-- Error -->
    </modules>
</project>

mvn package results in:

Child module trunk\project-commons of trunk\pom.xml does not exist
like image 810
membersound Avatar asked Sep 30 '22 16:09

membersound


1 Answers

If you run mvn install on that global project, it will be installed in your local repository. Your other projects can then reference it as a dependency:

<dependency>
  <groupId>whatever</groupId>
  <artifactId>project-commons</artifactId>
  <version>1.0</version>
</dependency>

The downside of this simplistic approach is that your other projects won't compile until you've checked-out project-commons and run mvn install.

A more advanced approach is to deploy a network-accessible repository (such as Artifactory or Nexus) which you can deploy global artifacts to. Artifactory has a community edition which is free. You can then list this repository in your settings file and Maven will resolve artifacts that are uploaded to it.

like image 119
Duncan Jones Avatar answered Oct 04 '22 19:10

Duncan Jones