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.