How to create multiple Maven artifacts from one source

I understand that this is against the best practices of maven, but perhaps my situation is one of the few exceptions to the rule - at least I'm stuck in thinking about alternatives :(

Wednesday:

  • We have a legacy application with its own technological interfaces for the outside world.
  • we want to use flash as a new interface
  • based on an outdated interface, we generate flash classes and pack them into flash-swc, which will be used by third-party developers.
  • Based on the deprecated interface, we generate Java classes that connect Flash service requests (coming through blazeds) to our deprecated interface.
  • to make it more complex, we don’t want / cannot use pom for it for each interface, since we have dozens of them (interfaces), and they will differ only from their artifactId. Instead, I use the "general" project structure, which will be parameterized (by jenkins) for each assembly. The project will be used only in a fully automated environment.

At first I tried to put all this in one β€œsimple” project, which works to such an extent that artifacts must be installed.

My current approach is a multi-module project structure inspired by a link to chapter 13 of the maven chapter, which has some drawbacks:

GenericProject | +-- GenerateSources from legacy interface | +-- pom.xml | +-- Java | +-- pom.xml | +-- SWC | +-- pom.xml | +-- pom.xml 

This approach has the disadvantage that I have links from "Java" and "SWC" to the internal "GenerateSource" structure, which is ugly but tolerable.
What really bothers me is that I have to tweak the installation and deployment plugins a lot to get artifacts with the name and version of the legacy interface that caused the whole process. Now I run it, but it looks very fragile.

I considered splitting / duplicating a project in two simple projects:

  • GenerateSources and Java
  • GenerateSources and SWC

But that would only allow minor annoyance with cross-references.

As Aaron noted in his comment, I am unclear in the statement of the problem. After several experiments, it became much clearer: In fact, I have two problems to solve

  • set / deploy two artifacts together
  • name artifacts other than project.artifactId

Any suggestions to make the whole process more like maven?

Thanks in advance.

+4
source share
3 answers

After some workarounds using the multi-module approach, I came to the following pragmatic solution:

  • use build-helper-plugin to install a secondary artifact that will be installed / deployed automatically
  • two-phase assembly:

    2.1 create pom.xml via sed that contains the allowed project.artifactId and project.version

    2.2 run maven build

Although you can theoretically use expressions like project.artifactId and project.version , maven gives you a warning for this. For a good reason: When you try to reference produced artifacts, nexus will give you "Could not read the artifact descriptor for ...". error. I suspect that this is due to the fact that expressions remain unresolved in the saved folder in the repository!

+3
source

You should write a small Maven plugin that you attach to the generate-sources phase. See maven-annotation-plugin for an example ( main class ).

This will include the generated sources at the output of the GenerateSource , and you can use these classes by simply including the dependency in other POMs. Note that you must create these files in target/ , and not in src/ .

As for installation / deployment: these plugins get their names from plugins that create artifacts. So there must be something wrong with the way you set the property. In your case, the JAR plugin. The documentation has an example of how to set the default artifact name .

+2
source

Try using Maven overlays to use resources between multiple web applications.

http://maven.apache.org/plugins/maven-war-plugin/overlays.html

+1
source

Source: https://habr.com/ru/post/1348057/


All Articles