0

I have an Android project. This project have another two other projects of my company added. To do that, in Android, I made right click on the project, then selected properties, then android, then libraries, then click add button and selected the two local folders where the projects are placed.

After do that, when I compile my project, android compile the other two projects and "automatically" are added to my project.

Now, I need to do the same, but using Maven. How can i do?

Thanks for your help and sorry for my poor english

Mark Comix
  • 1,878
  • 7
  • 28
  • 44

2 Answers2

0

If all of the projects are Maven projects then you can easily create a multi module project. Check this guide for details. The TL;DR would be to add a parent pom which would look something like this:

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>your.group.id</groupId>
    <artifactId>your-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <name>Multi Module Parent Example</name>

    <modules>
        <module>android-app</module>
        <module>other-project1</module>
        <module>other-project2</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Then you have a directory structure like this:

my-projects/
| pom.xml <-- The above pom
| android-app/
+-+ pom.xml
| \ ...
| other-project1/
+-+ pom.xml
| \ ...
| other-project2/
+-+ pom.xml
  \ ...

EDIT: If you want to include jars from non-Maven projects into your build automatically, check out this question and its accepted answer. The TL;DR here is to add something like this to your pom:

<dependency>
    <groupId>test</groupId>
    <artifactId>own-project1</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>../own-project1/target/own-project1.jar</systemPath>
</dependency>
<dependency>
    <groupId>test</groupId>
    <artifactId>own-project2</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>../own-project3/target/own-project3.jar</systemPath>
</dependency>
Community
  • 1
  • 1
blalasaadri
  • 5,990
  • 5
  • 38
  • 58
0

Either you dependent projects are maven projects, so there will be no additional staff to do and here where maven makes things easier and you can simply declare a dependency to other projects:

<project>
  <groupId>your.group.id</groupId>
  <artifactId>your-artifact-id</artifactId>
  ...
  <dependency>
    <groupId>some.group.id</groupId>
    <artifactId>some-artifact-id</artifactId>
    <version>1.0</version>
  </dependency>
</project>

Or when the dependent modules are non mavenized projects, you can install the archives (jars) to your local repository so they can be later used as maven dependencies:

mvn install:install-file -Dfile=PATH_TO_JAR_FILE.jar -DgroupId=some.group.id -DartifactId=some-artifact-id -Dversion=1.0 -Dpackaging=jar

Then the upside pom.xml file snapshot remain legal.

tmarwen
  • 15,750
  • 5
  • 43
  • 62