Thomas
Thomas

Reputation: 71

How to produce Multiple Maven Artifacts from one Source

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

The environment is this:

First I've tried to put all these in one "simple" project, which works up to the point where the artifacts should get installed.

My current approach is a multimodule project structure inspired by maven reference chapter 13, which has some disadvantages on it's own:

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

This approach has the disadvantage, that I have references from "Java" & "SWC" to the internal structure of "GenerateSource" which is ugly but tolerable.
What really gets in my way is that I have to heavily tweak the install & the deploy plugins to get artifacts with the name & version of the legacy interface which triggered the whole process. I got it running now, but it looks very brittle.

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

But this would only solve the minor annoyance with the cross-references.

As Aaron pointed out in his comment, I'm unclear in stating the problem. After some more experiments this got a lot clearer to me: Essentially I have two problems to solve

  1. install/deploy two artifacts together
  2. name the artifacts different than the project.artifactId

Any suggestions to make the whole process more maven-like?

Thanks in advance.

Upvotes: 4

Views: 3388

Answers (3)

Thomas
Thomas

Reputation: 71

After some detours with the multimodule approach I came to the following pragmatic solution:

  1. use the build-helper-plugin to attach a secondary artifact to be installed/deployed automaticly
  2. two-phase build:

    2.1 generate a pom.xml via sed which contains resolved project.artifactId & project.version

    2.2 run the maven build

Although you theoretically can use expressions as project.artifactId & project.version, maven gives you a warning for this . . . for a good reason: When you try to reference the produced artifacts, nexus will give you a "Failed to read artifact descriptor for . . ." error. I suspect this is because in the stored pom in the repository the expressions are unresolved!

Upvotes: 3

Arpit
Arpit

Reputation: 6260

Try using Maven overlays, it's used to share resources between multiple web applications.

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

Upvotes: 1

Aaron Digulla
Aaron Digulla

Reputation: 328810

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

That will include the generated sources in the output of the GenerateSource and you can consume those classes just by including the dependency in the other POMs. Note that you should create those files under target/, not in src/.

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

Upvotes: 2

Related Questions