2

I have three Maven projects (A, B, and C) that generate library JAR files. C depends on B, and B depends on A. Projects A and B are jars that have some required configuration files (XML/XSD files) that must be present when I use Project C (a library jar). An executable project D depends explicitly on project C. When D is run, any configuration files required by projects A, B, and C must be present in a specific directory.

  D
  |runtime
  v
  C ----- compile -----> B ----- compile -----> A
  |                      |runtime               |
  |runtime               v                      |runtime
  +----------> /spec-dir/*.xml|*.xsd <----------+
                              ^
                              |
                       +------+-----+
                       | extract at |
                       | C's build  |
                     A.tar.gz    B.tar.gz

Background: I'm currently bundling the configuration files for A and B using the maven-assembly-plugin and attaching it as a tar.gz assembly to artifacts A and B like so:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  <id>config</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>${basedir}/config</directory>
      <outputDirectory>config/</outputDirectory>
      <includes>
        <include>*</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

Ideally I only want to define a dependency to B in C's pom file (without having to add explicit dependencies to A and B's 'config' classifiers).

Question 1:

Is it possible in a development environment to automagically extract the configuration files from A and B's tar.gz to an output directory when I build Project C? Note that if those files already exist, I do NOT want to overwrite them (but rather use the XML/XSD files that are already there). I could explicitly unpack it by adding a maven-dependency-plugin:unpack to project C's pom file, but I'd rather not since project B will in reality be included in 50 other projects:

        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifact>GROUP_ID:PROJECT_B:VERSION:tar.gz:config</artifact>
                        <outputDirectory>${env.CONFIG_DIR}</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Question 2:

In a deployment environment, how can I aggregate the configuration files for projects A, B, and C into a 'staging' area where they can then be bundled for installation? Again, I don't want to have to explicitly "unpack" each dependency with a 'config' classifier.

Patrick
  • 41
  • 2
  • A picture is worth a thousand words: Does the chart I added reflect your situation properly? – Gerold Broser Feb 16 '17 at 16:34
  • 1
    Almost...(and thanks for the cleanup!) In the "extract at C's build", I want to extract A.tar.gz and B.tar.gz, not from the jars. – Patrick Feb 16 '17 at 16:54
  • Here's a thought... When I build B, could I include A's configuration as part of B.tar.gz? Then when I build C, could I include the contents of B.tar.gz in C.tar.gz? Because the artifacts are versioned, a specific version of C.tar.gz should properly represent the configuration dependencies inherited from A and B. – Patrick Feb 16 '17 at 18:06
  • What are there config files for? – Michael-O Feb 16 '17 at 19:43
  • What do you exactlxy mean by "_B ... included in 50 other projects_" in Q1? These 50 have B as dependency? Your thought sounds reasonable. Is it clear to you how to do this? – Gerold Broser Feb 17 '17 at 17:20

0 Answers0