multi artifact id in one pom

非 Y 不嫁゛ 提交于 2019-12-02 04:17:25

问题


There is a maven project(jar), but now it needs to be spilt into two artifacts

I want to have two maven artifact like following

<groupId>xxx</groupId>
<artifactId>xxx-client</groupId>

<groupId>xxx</groupId>
<artifactId>xxx-impl</groupId>

But all the code is in one single project.

My question would be, How can I package the tow required artifacts without changing the project too much.

Then ,

mvn package deploy

will auto deploy these two artifacts into repository Actually I don't want to split these project into two maven project.


回答1:


I am not sure if there is a possibility of having two <artifactId> tags in one POM, since it is unique. What you may do is, you can have two pom files, say, pom.xml, and pom_impl.xml, now

  • to deploy client do, mvn package deploy
  • to deploy impl do, mvn -f pom_impl.xml package deploy

Never tried though.


Clarification: The question seem ambiguous, seems like you have one project but you wanted to generated two artifacts (client, and impl) of the same code-base. On reading it again, I feel like you have two projects (two different code base) but you just wanted to unify it so that it behaves as two modules of the same project. My answer assumes the first case.




回答2:


If I understood the question correct, you need to have a super pom (xxx/pom.xml) and two different poms for both of your projects (xxx-client and xxx-impl). The structure of your super pom will be 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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>xxx</groupId>
    <artifactId>xxx</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>xxx-client</module>
        <module>xxx-impl</module>
    </modules>
</project>

Then when you deploy your main pom, it will deploy it's modules as well.

Here are references if you want to read more about super pom and modules.




回答3:


This is called "multi module project" in the Maven world. You can find information on how to do this e.g. here. Indeed you need two separate POMs and an additional one to combine both.




回答4:


specify pom

Make two pom ,then specify the pom in command line, that is the easiest way.



来源:https://stackoverflow.com/questions/9075259/multi-artifact-id-in-one-pom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!