Skip to main content

Runtime Dependencies

Some ExpandersExpanderA unit of generation that combines a data tree instance (functional M1 model) with a template to generate an artifact. will require runtime libraries to be added to the expanded project. These libraries can be defined declaratively.

To do so, we need to define:

  • a list of libraries
  • a LayerImplementation that attaches the libraries to a LayerType.

For a guide on how to use LayerImplementations in expandersExpanderA unit of generation that combines a data tree instance (functional M1 model) with a template to generate an artifact., see this article.

Library​

A library has a unique name, a groupId, artifactId and version.

<dataResource type="elements::Library">
<library name="solr-solrj">
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>9.2.1</version>
<technology name="APACHE SOLR"/>
<type>runtime</type>
</library>
</dataResource>

Type can be declared as one of the 3 following types:

  • runtime: needed during runtime
  • compilation: only needed during compilation (will not be included in the .ear file)
  • test: only needed during test

If you have a LayerImplementation, you can attach a Library:

<dataResource type="elements::LayerImplementation">
<layerImplementation name="Solr Search">
<technology name="APACHE SOLR"/>
<condition>component.getOption('solr.includeSearch').defined</condition>
<layerDependencys>
<layerDependency>
<library name="solr-solrj"/>
</layerDependency>
</layerDependencys>
</layerImplementation>
</dataResource>

A dependency will be added to the pom.xml file of that layerLayerLogical separation of functionality within a single system/application, focused on code organization..

Filtered Resources​

It can be useful to insert versions into the libraries.xml file using maven filtering.

  1. In your pom.xml, define 2 resources in <build>:
<project>
...
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
...
</project>
  1. Move your libraries.xml file to resources-filtered.
  2. Replace the version of the library with a placeholder:
<dataResource type="elements::Library">
<library name="solr-solrj">
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
<technology name="APACHE SOLR"/>
<type>runtime</type>
</library>
</dataResource>
  1. Define a property in your pom.xml defining the version:
<properties>
<solr.version>9.2.1</solr.version>
</properties>