lucky_start_izumi
lucky_start_izumi

Reputation: 2591

about generate maven dependency

I am pretty new to maven. Now I have a maven project developed. My another project needs to depend on this one. Does anyone know how can I generate my own dependency? So that my second project can add the first one as a dependency in pom. thank you very much

Upvotes: 0

Views: 56

Answers (2)

Chris
Chris

Reputation: 23179

Since your first project is already a maven-project, just install it in your local repository by running mvn install in the first project's root directory.

Then you can include a dependency in your second project by simply referencing the groupId, artifactId and version you defined in the first project.

So if your first project had the following in its pom:

    <project>
        <groupId>com.yourdomain</groupId>
        <artifactId>yourcomponent</artifactId>
        <version>1.0</version>
    ... <!-- more here -->

you can include this in your second project:

    <dependencies>
       <dependency>
            <groupId>com.yourdomain</groupId>
            <artifactId>yourcomponent</artifactId>
            <version>1.0</version>
       </dependency>
    </dependencies>

Unless you deploy your project 1 jar to a central maven repository, this will only work if your jar is in your local repository (via mvn install).

Upvotes: 2

Miquel
Miquel

Reputation: 15675

Maven projects are identified by the "Maven coordinates", that is, the ArtifactID, GroupID and version.

Say you create your first project and run maven install. Your local repository (in $HOME/.m2/) will now contain the compiled project plus whatever coordinates you put in there.

Your second project must now only depend on the said coordinates.

I would suggest googling a bit on maven. I made a tutorial a long time ago that might help you, even if the examples are a little simple. Here you go and good luck!

Upvotes: 1

Related Questions