Maven: generates multiple "artifacts" with the same pom file?

I have a project here that currently uses one pom.xml ( link ) to create one "artifact".

What I would like to do is split the project, call it p, into:

  • p-core, which contains the main verification process;
  • p-format, which contains the "format" keyword check, which depends on the p-kernel.

The reason I want to do this is because of the dependencies: p-format pulls over 70% of them by volume alone, and not all uses of JSON Schema require format support anyway.

Do I need to create two completely separate projects, or can I use one pom.xml to generate these two artifacts? I assume the latter is doable as many projects already do this (Jackson for example).

[In case it makes any difference, I post via Sonatype maven repo]

+10


source to share


4 answers


You should create two seperated projects (two seperated POMs), but it would probably be a good idea to create a common parent for them that also bundles them together as modules. See the Inheriting Projects and Aggregating Projects sections of Introduction to POM for some basics.



It is never recommended in Maven to try to hack it so that it will produce many different artifacts from the same POM.

+9


source


Your life will be much easier if you just rip out the p-format into a separate project that depends on the p-core.

While there are ways to publish multiple artifacts for each project, Maven is designed around one artifact per pom / module (plus test artifacts). From experience, smart attempts to bypass this design point end up biting you in the end - usually in the form of a problem 6 months after the packaging doesn't work properly on any machine.



The scenario you describe works well for a multi-project use case and I suggest you go with the flow and make your future happy.

+3


source


You can use the maven-Assembly plugin . If two artifacts have overlapping classes and one always needs to update the other to update, then this is a good choice.

You have to think about the life cycle of artifacts. Should both artifacts have the same version number? Do you want to publish a new version of p-core whenever you fix a p-format bug? Is P-core useful on its own?

My guess is that the build plugin should primarily be used to provide different packaging for the same artifact.

+3


source


I had a similar case, and I agree with Michal's proposal. However, I would like to expand the proposed solution further:

I am assuming p has a single origin and both p-core and p-format are generated from it. So you have to create a parent POM for p with child modules (with corresponding POMs) - one for "core" and one for "format", but both originate from parent / src /.

So we separate the build processes for "core" and "format" to generate specific artifacts, but not to replicate the original sources for p.

Maven supports but does not recommend this approach, but I don't understand why they shouldn't. In my opinion its a structured, clean and caring separation with no long-term consequences and there is no better alternative.

http://maven.apache.org/guides/mini/guide-using-one-source-directory.html

0


source







All Articles